Skip to content
Math

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.

Your details

Switch between forward (log) and inverse (antilog / 2^y) direction.
Must be a positive number. log2(0) and log2 of negatives are undefined.
log₂(x)Yes - 2^8
8

The base-2 logarithm of your input

x = 2^y (antilog)256
Bits needed8bits
Exact power of 2Yes - 2^8
Nearest lower power of 2256
Nearest upper power of 2256
897.7% below · x
-32.580128256
x

log₂(256) = 8.000000

  • 256 is an exact power of 2. That means log₂(256) is a whole number: 8.
  • To store or index 256 distinct values in binary you need at least 8 bits (because 2^8 = 256).
  • The binary logarithm is the inverse of exponentiation base 2: if log₂(x) = y, then 2^y = x. This is why log₂(256) = 8, since 2^8 = 256.

Next stepIn computer science, log₂ appears everywhere: hash table sizing, binary search depth, Huffman coding, and Shannon entropy all rely on it. If you need log in another base, use the change-of-base rule: log₂(x) = log(x) / log(2).

Formula

log2(x)=lnxln2=log10xlog102log_2(x) = \dfrac{\ln x}{\ln 2} = \dfrac{\log_{10} x}{\log_{10} 2}

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^ylog₂(x)Computing context
-30.125 (1/8)-3
-20.25 (1/4)-2
-10.5 (1/2)-1
010Empty set / false
1211 bit: 2 states
2422 bits: 4 states
3833 bits: octal digit
41644 bits: hex nibble
53255 bits: 32 options
66466 bits: ASCII subset
712877-bit ASCII
825681 byte (8 bits)
101024101 KiB (kibibyte)
16655361616-bit integer range
201048576201 MiB (mebibyte)
32~4.29 billion3232-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.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…