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.

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, it is monotonically increasing, and it is negative for 0<x<10 < x < 1.

Listing the points it passes through shows that the value gains exactly 11 each time xx doubles.

  • (1,0)(1, 0): log21=0\log_2 1 = 0
  • (2,1)(2, 1): log22=1\log_2 2 = 1
  • (4,2)(4, 2): log24=2\log_2 4 = 2
  • (8,3)(8, 3): log28=3\log_2 8 = 3
  • (12,1)\left(\dfrac{1}{2},\, -1\right): log212=1\log_2 \dfrac{1}{2} = -1

As x0+x \to 0^{+} it diverges to -\infty, so the yy-axis (x=0x = 0) is a vertical asymptote; as x+x \to +\infty it keeps rising slowly to ++\infty. The derivative y=1xln2y' = \dfrac{1}{x \ln 2} is always positive and the second derivative is negative, so the graph is concave.

By the change-of-base formula, log2x=lnxln21.4427lnx\log_2 x = \dfrac{\ln x}{\ln 2} \approx 1.4427\,\ln x, merely a constant multiple of the natural logarithm. Thus it differs from lnx\ln x or log10x\log_{10} x only by a vertical stretch and has the same shape.

The base-2 logarithm is especially important in computer science. The unit of information, the bit, is measured with log2\log_2: distinguishing nn alternatives requires log2n\log_2 n bits. Algorithms that repeatedly halve a problem, such as binary search and merge sort, run in O(log2n)O(\log_2 n) time, and it also appears when measuring a musical octave (a doubling of frequency).