Log Base 2 Calculator (Binary Logarithm)
Enter any positive number to calculate its base-2 logarithm. You can also work in reverse: enter the logarithm result to find the original value. The calculator shows the change-of-base formula with your actual numbers, flags exact powers of 2, computes the bits needed to represent that many values, and draws a live curve so you can see where your result sits.
Formula
Worked example
Find log2(256): ln(256) / ln(2) = 5.5452 / 0.6931 = 8 exactly. Check: 2^8 = 256. Because 256 is an exact power of 2, the result is a whole number. For log2(100): ln(100) / ln(2) = 4.6052 / 0.6931 = 6.6439. Check: 2^6.6439 = 100.
What is log base 2 (the binary logarithm)?
The base-2 logarithm, written log₂(x) or lb(x), asks the question: "To what power must I raise 2 to get x?" For example, log₂(8) = 3 because 2^3 = 8. It is the inverse of the exponential function 2^y. The binary logarithm is the natural logarithm of mathematics in binary: it describes how information content, decision depth, and storage scale with powers of 2. Every time x doubles, log₂(x) increases by exactly 1.
How to calculate log base 2
Most scientific calculators do not have a dedicated log₂ button, but you can compute it with any logarithm using the change-of-base rule: log₂(x) = ln(x) / ln(2) = log(x) / log(2). On a calculator that has natural log (ln), compute ln(x) and divide by ln(2) = 0.693147. On one with only log (base 10), compute log(x) and divide by log(2) = 0.30103. For example, log₂(100) = log(100) / log(2) = 2 / 0.30103 = 6.644.
Why log base 2 matters in computing
Binary is the native language of computers: each bit holds exactly two states (0 or 1). As a result, log₂ shows up constantly in computer science. A binary search over n elements takes at most ceil(log₂(n)) comparisons. A balanced binary tree of n nodes has depth floor(log₂(n)). Storing n distinct values requires ceil(log₂(n)) bits. Shannon entropy measures information in bits using log₂. Hash table sizes, FFT algorithms, Huffman coding, and countless data structures rely on powers of 2, making log₂ the natural unit of digital information.
Logarithm properties useful for log₂
The standard logarithm identities hold for any base including 2. Product rule: log₂(a * b) = log₂(a) + log₂(b). Quotient rule: log₂(a / b) = log₂(a) - log₂(b). Power rule: log₂(a^n) = n * log₂(a). Identity: log₂(2) = 1, log₂(1) = 0. Inverse: 2^(log₂(x)) = x. These let you split complex expressions into simpler parts or move between bases.
Common powers of 2 and their log₂ values
| Exponent (y) | x = 2^y | log₂(x) | Computing context |
|---|---|---|---|
| -3 | 0.125 (1/8) | -3 | |
| -2 | 0.25 (1/4) | -2 | |
| -1 | 0.5 (1/2) | -1 | |
| 0 | 1 | 0 | Empty set / false |
| 1 | 2 | 1 | 1 bit: 2 states |
| 2 | 4 | 2 | 2 bits: 4 states |
| 3 | 8 | 3 | 3 bits: octal digit |
| 4 | 16 | 4 | 4 bits: hex nibble |
| 5 | 32 | 5 | 5 bits: 32 options |
| 6 | 64 | 6 | 6 bits: ASCII subset |
| 7 | 128 | 7 | 7-bit ASCII |
| 8 | 256 | 8 | 1 byte (8 bits) |
| 10 | 1024 | 10 | 1 KiB (kibibyte) |
| 16 | 65536 | 16 | 16-bit integer range |
| 20 | 1048576 | 20 | 1 MiB (mebibyte) |
| 32 | ~4.29 billion | 32 | 32-bit unsigned int |
These values appear frequently in computing (memory sizes, algorithm complexity, bit widths).
Frequently asked questions
What is log base 2 of 0?
log₂(0) is undefined. As x approaches 0 from the positive side, log₂(x) approaches negative infinity. The logarithm requires a strictly positive input; zero and negative numbers have no real logarithm.
What is log₂(1)?
log₂(1) = 0. This is because 2^0 = 1. Any base raised to the power of 0 equals 1, so the logarithm of 1 in any base is always 0.
How is log₂ different from ln and log₁₀?
All three are logarithms but with different bases. ln is base e (~2.71828), log₁₀ is base 10 (the common log on most calculators), and log₂ is base 2. They are proportional: log₂(x) = ln(x) / ln(2) = log₁₀(x) / log₁₀(2). In computer science, log₂ is preferred because it counts bits. In information theory the unit is the bit; in natural-log information theory the unit is the nat.
How many bits do I need to store n values?
You need ceil(log₂(n)) bits. For example, to represent 256 distinct values you need log₂(256) = 8 bits exactly. For 257 values you still need 9 bits, because 2^8 = 256 < 257, so 8 bits are not enough. This calculator shows the bit count automatically for any x you enter.
Can log₂ produce negative or fractional results?
Yes. For any x between 0 and 1 the result is negative (e.g. log₂(0.5) = -1 because 2^-1 = 0.5). For x between 1 and 2 the result is between 0 and 1. Only exact integer powers of 2 (1, 2, 4, 8, 16, ...) produce whole-number results.