What is a Logarithm?
As soon as humanity learned to add numbers, it found a way to simplify repeated addition — multiplication. Then came exponents to simplify repeated multiplication. The logarithm is the natural next step: the inverse of exponentiation.
The logarithm loga(b) answers the question: "To what power must we raise a to get b?" For instance, log2(8) = 3, because 2³ = 8.
Binary Logarithm (Log Base 2)
The binary logarithm, written log2(x), is a special case of the logarithm where the base is 2. It asks: to what power must 2 be raised to obtain x?
- log2(1) = 0 because 2⁰ = 1
- log2(2) = 1 because 2¹ = 2
- log2(4) = 2 because 2² = 4
- log2(8) = 3 because 2³ = 8
- log2(16) = 4 because 2⁴ = 16
- log2(32) = 5 because 2⁵ = 32
When x is not an exact power of 2, the result is a non-integer. For example, log2(10) ≈ 3.3219.
Formula and Calculation
The binary logarithm can be computed using the change-of-base formula:
- log2(x) = ln(x) / ln(2)
- log2(x) = log10(x) / log10(2)
- log2(x) = log10(x) / 0.30103
Metric vs. Binary (US) Measurement Systems
The binary logarithm is closely tied to two competing systems for measuring digital data:
Metric System (SI Prefixes)
In the metric system, prefixes follow powers of 10:
- 1 KB (kilobyte) = 1,000 bytes → log2(1,000) ≈ 9.9658
- 1 MB (megabyte) = 1,000,000 bytes → log2(1,000,000) ≈ 19.9316
- 1 GB (gigabyte) = 1,000,000,000 bytes → log2(10⁹) ≈ 29.8974
This system is used by storage manufacturers (hard drives show capacity in metric gigabytes).
Binary System (IEC / US Computing Prefixes)
In computing, data is natively organized in powers of 2, giving rise to binary prefixes:
- 1 KiB (kibibyte) = 1,024 bytes = 2¹⁰ → log2 = 10
- 1 MiB (mebibyte) = 1,048,576 bytes = 2²⁰ → log2 = 20
- 1 GiB (gibibyte) = 1,073,741,824 bytes = 2³⁰ → log2 = 30
This is why binary logarithm results are always exact integers for binary memory sizes like RAM, cache, and address spaces.
Practical Applications of log₂
Computer Science & Information Theory
- Bits needed: To represent n distinct values you need ⌈log2(n)⌉ bits. E.g., to represent 256 colors: log2(256) = 8 bits.
- Binary search: The number of steps to find an item in a sorted list of n elements is ⌊log2(n)⌋ + 1.
- Tree height: A balanced binary tree with n nodes has height ⌊log2(n)⌋.
Music Theory
In music, an octave doubles the frequency. So log2(f₂/f₁) gives the number of octaves between two frequencies. For example, from 440 Hz (A4) to 880 Hz (A5): log2(880/440) = log2(2) = 1 octave.
Physics & Chemistry
Binary logarithms appear in entropy calculations (information entropy in bits), some quantum mechanics formulas, and half-life problems expressed in terms of doublings.
Key Properties of log₂
- log2(1) = 0 (any base raised to 0 gives 1)
- log2(2) = 1 (base raised to 1 gives itself)
- log2(x · y) = log2(x) + log2(y) (product rule)
- log2(x / y) = log2(x) − log2(y) (quotient rule)
- log2(xⁿ) = n · log2(x) (power rule)
- log2(x) is only defined for x > 0
FAQs
What is log₂ 16?
log2(16) = 4, because 2⁴ = 16.
What is log₂ 32?
log2(32) = 5, because 2⁵ = 32.
What is log₂ of a negative number?
The binary logarithm is undefined for negative numbers and zero. It is only defined for positive real numbers.
What is the difference between log₂ and log₁₀?
log10 (common logarithm) uses base 10, while log2 (binary logarithm) uses base 2. They are related by: log2(x) = log10(x) / log10(2) ≈ log10(x) / 0.30103.
How many bits do I need to store 1,000 values?
You need ⌈log2(1000)⌉ = ⌈9.9658⌉ = 10 bits to represent 1,000 distinct values (since 2¹⁰ = 1,024 ≥ 1,000).