Math Fundamentals18 sections · 814 units
Open in Course

Binary Logarithm (Base 2)

Most common in CS

The binary logarithm log2(n)\log_2(n) is the most common logarithm in computer science. It tells you how many times you can divide nn by 22 before reaching 11.

For example, log2(64)=6\log_2(64) = 6. You can halve 6464 six times: 643216842164 \to 32 \to 16 \to 8 \to 4 \to 2 \to 1. Each division is one step, so six divisions means log2(64)=6\log_2(64) = 6.

This is why binary search runs in O(logn)O(\log n) time. Each comparison cuts the search space in half, and you can only halve nn about log2(n)\log_2(n) times before you find your answer.