Log Base 2 Calculator

Take the base-2 logarithm of any positive number, with the floor, the ceiling and the bit length kept apart — because those are three different questions and all three get called log2. Base 2 is the one logarithm that comes out exact. A double is stored as a fraction multiplied by a power of two, s...

log₂ x = the number of doublings from 1 to x

Equivalently, how many times x can be halved before it reaches 1. Where that count comes out whole, this logarithm is exact — and computing it as ln x ÷ ln 2 is what throws the exactness away.

THE NUMBER

LOG BASE 2 · EXACT

10

x is exactly 2 to the power 10, so this answer carries no rounding at all — the exponent was already stored in the number.

FLOOR

10

CEILING

10

BIT LENGTH

11

This is the case where a logarithm is exact rather than approximated. A double is stored as a fraction times a power of two, so for a power of two the answer is already sitting in the number and only has to be read out. That is unique to base 2 — ln 8 and log₁₀ 8 are both irrational, and no amount of care recovers a clean value that was never there. Note that 1024 needs 11 binary digits to write down even though its logarithm is 10; those are two different questions and the panel below keeps them apart.

QuantityValueWhat it answers
log₂ x10doublings from 1 to x
⌊log₂ x⌋10complete doublings, ignoring the remainder
⌈log₂ x⌉10bits to store x distinct values
bit length11 (10000000000)binary digits needed to write x
ln x6.93147180559945the same number scaled by ln 2
log₁₀ x3.01029995663981decimal digits, roughly
ln x / ln 210agrees here, but not always

Floor, ceiling and bit length are three different questions. To store 1024 distinct values you need 10 bits. To write the number 1024 in binary you need 11 digits. And 10 is the position of its highest set bit. All three get called “log base 2” in conversation, and mixing them up is the most common source of off-by-one errors in code that allocates buffers or sizes hash tables.

THE HALVINGS

LOG BASE 2 COUNTS THE HALVINGSeach row halves the one above; count the rows to the green onelog2 = 10.000000that count is the whole part; the green leftover between 1 and 2 supplies the fraction

Count the rows and you have the logarithm. Each halving takes exactly one off it, which is why the answer for a power of two is a whole number and why the whole part is simply how many complete halvings fit.

WHAT DIVIDING TWO LOGARITHMS COSTSeach cell is one value; red means log(x)/ln2 disagreed with the dedicated routinepowers of two, 2⁰ to 2⁵² — 5 of 53 wrongthe integers 1 to 53 — 15 of 53 disagreethe gaps are tiny, but they land on the exact powers, where a floor turns them into an off-by-oneacross all 2098 representable powers of two your engine misses 441; this page does not use it
THREE DIFFERENT QUESTIONS, ALL CALLED LOG21024 in binary is 11 digits long110

Live calculation · updates as you type

Created with❤️byeaglecalculator.com

HOW TO USE

  1. 1

    Type any positive number into x. The logarithm appears immediately, and if x is a power of two the panel says so — that answer carries no rounding at all, because the exponent was already stored in the number.

  2. 2

    Read the floor, ceiling and bit length as three separate answers. To store x distinct values you need the ceiling; to write x in binary you need the bit length; the floor is the position of its highest set bit. They are not interchangeable.

  3. 3

    Watch the middle panel if you were about to compute this as ln x ÷ ln 2. It marks in red every value where that division disagrees with the dedicated routine, computed live rather than quoted, and the disagreements sit on the powers of two.

  4. 4

    Drag the slider to step through the halvings. Counting the rows gives the whole part of the logarithm directly, and the green row at the end — the leftover between 1 and 2 — is what supplies the fractional part.

REFERENCE FORMULAS

RuleFormulaWhat it is for
Definitionlog₂ x = y means 2ʸ = xHow many doublings from 1 reach x, or how many halvings of x reach 1.
Change of baselog₂ x = ln x / ln 2True, but do not compute it this way: the division loses the exact integers.
Exact caselog₂(2ᵏ) = kExact for every representable k, because a double already stores its exponent.
Bits to write n⌊log₂ n⌋ + 1The number of binary digits. For 8 this is 4, since 8 is 1000.
Bits to store n values⌈log₂ n⌉Different question, often a different answer. For 8 distinct values, 3 bits.
Doublinglog₂(2x) = log₂ x + 1Each doubling adds exactly one. This is why log scales in base 2 are readable.
Productlog₂(ab) = log₂ a + log₂ bMultiplication becomes addition, as in any base.
Binary search⌈log₂ n⌉ comparisonsThe worst case for finding an item among n sorted ones by halving.
Informationlog₂ n bitsThe information in choosing one of n equally likely outcomes, measured in bits.
Inverse2^(log₂ x) = xRound-tripped on this page and reported in units in the last place.

FREQUENTLY ASKED QUESTIONS

RELATED CALCULATORS

MORE ALGEBRA CALCULATORS

Was this calculator helpful?

Last updated: August 3, 2026 · Computed with the dedicated base-2 routine, never by dividing two logs · checked against a 60-digit series