Log Base 2 Calculator
The binary logarithm — how many times you double from 1 to reach your number, and the bits it takes to store it.
log₂(x) answers "2 to what power gives x?".
How the log base 2 calculator works
log₂(x) answers "2 to what power gives x?". It is the logarithm of computing: the number of bits needed to represent x distinct values is log₂(x) rounded up, and the number of halvings a binary search needs through n items is log₂(n). It is also the doubling count — anything growing by 100% each step reaches x after log₂(x) steps.
Formula: log_b(x) = ln(x) / ln(b)
Worked examples
| Inputs | log base b of x | Note |
|---|---|---|
| log₂ 1024 | 10 | 10 — ten doublings, and 10 bits |
| log₂ 256 | 8 | 8 — one byte |
| log₂ 1,000,000 | 19.9315685693 | 19.93 — so 20 bits |
FAQFrequently asked questions
What is log base 2?
The power you raise 2 to in order to get your number: log₂ 32 = 5.
How many bits do I need for n values?
log₂(n) rounded up — 1,000 values need 10 bits, since 2¹⁰ is 1,024.
Why does binary search take log₂ n steps?
Because each comparison halves what is left, so the count of halvings is the binary log.
What is log₂ of a million?
19.93, so a million values fit in 20 bits.
Is it related to doubling time?
Directly — anything that doubles each period reaches x after log₂(x) periods.
Where these figures come from
- NIST Digital Library of Mathematical Functions — reference definitions for elementary and special functions
- Wolfram MathWorld — definitions and formulas for every topic on this page
- NIST/SEMATECH e-Handbook of Statistical Methods — the statistical formulas (mean, variance, z, confidence intervals, sample size)
- National curriculum in England — Mathematics — the terms and methods taught in UK schools
Last checked: September 2026. Formulas are fixed by mathematics and do not change with tax years or regulations.