Logarithm calculator
Logarithms in any base, with the working. It uses the dedicated functions where they exist, because the standard change-of-base identity gives 2.9999999999999996 for the logarithm of a thousand. Nothing you type here leaves your browser — it is worked out on your own device, so there is nothing to send and nothing to log.
The identity everyone uses is lossy
There is only one logarithm function in most languages — the natural one — and every other base is reached by the change-of-base identity:
logb(x) = ln(x) ÷ ln(b)
The algebra is exact. The arithmetic is not, because ln(1000) and ln(10) are each rounded to the nearest double before the division happens:
| ln(1000) ÷ ln(10) | 2.9999999999999996 |
|---|---|
| Math.log10(1000) | 3 |
That is why every language ships a separate log10 and
log2 rather than leaving you to divide. This page uses them
for bases 10 and 2 and the natural log for base e, and goes
through the identity only for other bases — and it tells you which
route it took.
And now the part that catches people out. log2(8) is 3 under both routes. So is log3(243). Base 2 is the base anyone reaches for to test a logarithm, and it is the one base where the identity happens to land correctly — while base 10, the base almost everyone actually uses, does not.
The logarithm of something just above one
If you compute the logarithm of 1 + x for a small x, adding the 1 destroys the answer before the logarithm sees it. At x = 10−16 the sum rounds to exactly 1, and the logarithm of 1 is zero:
| Math.log(1 + 1e−16) | 0 |
|---|---|
| Math.log1p(1e−16) | 1e−16 |
This is not a curiosity. It is what happens whenever a small rate is compounded — interest, growth, pH, decibels, anything where the number you care about is the difference from one.
It has its own box above, and that is deliberate. You cannot reach this by typing a number just above 1, because every number you can type survives the round trip: take 1 away and add it back and you get what you started with. The loss happens to a small number that meets a 1 inside a calculation, so the box takes that small number directly. The two answers agree down to about 5×10−9 and part company below it.
Where to go next
- Root calculator
- Scientific notation converter
- Rounding calculator — the same binary problem, from the other end.
- Every tool on the site