y=log2xy = \log_2 x

Graph of the Binary Logarithm y=log2xy = \log_2 x

y=log2xy = \log_2 x is the logarithm with base 22: it gives the power to which 22 must be raised to obtain xx. For example 23=82^3 = 8, so log28=3\log_2 8 = 3. It is the inverse of the exponential y=2xy = 2^x.

Domain and range

The argument xx must be positive, so the domain is x>0x > 0 and the range is all real numbers. Since the base exceeds 11 the function increases monotonically, and it is negative for 0<x<10 < x < 1.

Doubling adds one

xxlog2x\log_2 x
12\dfrac{1}{2}1-1
1100
2211
4422
8833

Each time xx doubles, the value gains exactly 11.

Monotonicity and asymptote

As x0+x \to 0^{+} the function diverges to -\infty, so the yy-axis, the line x=0x = 0, is a vertical asymptote. As x+x \to +\infty it keeps rising slowly to ++\infty. The derivative is as follows.

y=1xln2y' = \frac{1}{x \ln 2}

It is always positive, and the second derivative is negative, so the graph is concave down. At (1,0)(1, 0) the tangent has slope y(1)=1ln21.4427y'(1) = \dfrac{1}{\ln 2} \approx 1.4427.

Symmetry with the exponential

The graph is symmetric to that of 2x2^x in the line y=xy = x: where 2x2^x shoots upward, log2x\log_2 x only creeps.

Change of base

By the change-of-base formula it is a constant multiple of the natural logarithm.

log2x=lnxln21.4427lnx\log_2 x = \frac{\ln x}{\ln 2} \approx 1.4427 \ln x

It therefore differs from lnx\ln x or log10x\log_{10} x only by a vertical stretch, and the shape is the same.

Applications

The base-22 logarithm is especially important in computer science.

  • The bit, the unit of information, is measured with log2\log_2
  • Distinguishing nn alternatives requires log2n\log_2 n bits
  • Binary search and merge sort, which halve the problem at every step, run in O(log2n)O(\log_2 n) time
  • A musical octave, a doubling of frequency, is measured the same way

Learning that an event of probability pp has occurred carries log2p-\log_2 p bits of information, which is the basis of Shannon entropy.