Math

Log Base 2 Calculator

Calculate logarithm base 2 (binary logarithm). Essential for computer science, information theory, and binary calculations.

log₂(256) = 8
log₂(x)
8
Input value
256
log₂(x)
8
log₁₀(x)
2.408240
ln(x)
5.545177
Power of 2?
Yes
2ⁿ where n =
8

log₂(x) answers: "2 raised to what power equals x?"

What is log base 2?

The binary logarithm (log₂) answers the question: "2 raised to what power equals x?"

log2(x)=y    2y=x\log_2(x) = y \iff 2^y = x

Formula

Using the change of base formula:

log2(x)=ln(x)ln(2)=log10(x)log10(2)\log_2(x) = \frac{\ln(x)}{\ln(2)} = \frac{\log_{10}(x)}{\log_{10}(2)}

Common values

xlog₂(x)
10
21
42
83
164
325
646
1287
2568
5129
102410

Applications in computer science

Bits needed to represent n values

bits=log2(n)\text{bits} = \lceil \log_2(n) \rceil

For example, to represent 100 different values, you need ⌈log₂(100)⌉ = 7 bits.

Binary search complexity

Binary search has O(log₂ n) time complexity, meaning each step halves the search space.

Tree depth

A balanced binary tree with n nodes has height ≈ log₂(n).

Information theory

Log base 2 is fundamental to information theory. The entropy (information content) is measured in bits:

H=pilog2(pi)H = -\sum p_i \log_2(p_i)

Properties

log2(1)=0log2(2)=1log2(xy)=log2(x)+log2(y)log2(x/y)=log2(x)log2(y)log2(xn)=nlog2(x)\begin{aligned} \log_2(1) &= 0 \\ \log_2(2) &= 1 \\ \log_2(xy) &= \log_2(x) + \log_2(y) \\ \log_2(x/y) &= \log_2(x) - \log_2(y) \\ \log_2(x^n) &= n \cdot \log_2(x) \end{aligned}