Translation unavailable - this article is shown in English. View English version
Summary
A logarithm answers the question: “What power must I raise this base to in order to get that number?” If b^y = x, then log_b(x) = y. Logarithms are the inverse of exponentiation, just as subtraction is the inverse of addition. They appear throughout science and engineering — the Richter scale (earthquakes), decibels (sound), pH (chemistry), and information theory (bits) all use logarithmic scales. This calculator computes logarithms in any base, including the two most common: base 10 (common logarithm, log) and base e (natural logarithm, ln).
How it works
The calculator uses the change-of-base formula to compute logarithms in any base. Since JavaScript natively provides Math.log (natural log, base e) and Math.log10 (common log, base 10), any other base is computed by converting:
- Common logarithm (log_10) — computed directly using Math.log10. Answers “10 raised to what power gives x?”
- Natural logarithm (ln) — computed directly using Math.log. Answers “e raised to what power gives x?” where e is approximately 2.71828.
- Custom base — uses the change-of-base formula: log_b(x) = ln(x) / ln(b). This works because if b^y = x, then y * ln(b) = ln(x), so y = ln(x) / ln(b).
The calculator also provides a verification step: it raises the base to the computed logarithm and confirms the result matches the original input (within floating-point precision).
Why logarithms matter
Logarithms convert multiplication into addition and exponentiation into multiplication. This property made them essential for computation before electronic calculators (via slide rules and log tables) and remains fundamental in:
- Computer science — algorithm complexity (O(log n) for binary search)
- Information theory — entropy measured in bits (log base 2)
- Finance — continuous compounding uses natural logarithms
- Signal processing — decibels use base-10 logarithms
- Chemistry — pH = -log_10[H+]
The formulas
Where
Where
Key logarithm identities
| Identity | Formula | Example |
|---|---|---|
| Log of 1 | log_b(1) = 0 | log_10(1) = 0 |
| Log of base | log_b(b) = 1 | ln(e) = 1 |
| Log of a power | log_b(b^n) = n | log_10(10^3) = 3 |
| Product rule | log_b(xy) = log_b(x) + log_b(y) | log(20) = log(4) + log(5) |
| Quotient rule | log_b(x/y) = log_b(x) - log_b(y) | log(5) = log(10) - log(2) |
| Power rule | log_b(x^n) = n * log_b(x) | log(1000) = 3 * log(10) |
Worked examples
Calculate log_2(8)
Ask: 2 raised to what power equals 8?
= 3
Verify using change-of-base formula
= 3
Verify by raising base to result
= Verified
Result
log_2(8) = 3 because 2^3 = 8
Calculate log_10(1000)
Ask: 10 raised to what power equals 1000?
= 3
Alternatively, count the zeros
= 3
Verify by raising base to result
= Verified
Result
log_10(1000) = 3 because 10^3 = 1000
Calculate ln(e^5)
Apply the power rule: ln(e^n) = n * ln(e)
= 5 * ln(e)
Recall that ln(e) = 1
= 5
Verify by computing e^5
= Verified
Result
ln(e^5) = 5 because e raised to the 5th power returns e^5
Inputs explained
- Argument (x) — the number you want to take the logarithm of. Must be positive; the logarithm of zero or a negative number is undefined in the real numbers. (Technically, logarithms of negative numbers exist in the complex plane, but this calculator handles real values only.)
- Base (b) — the base of the logarithm. Common choices are 10 (common log, written “log”), e (natural log, written “ln”), and 2 (binary log, written “lg” or “log_2”). Must be positive and cannot be 1 (because 1^y = 1 for all y, making the logarithm undefined).
- Preset bases — quick-select buttons for the three most common bases: 10, e, and 2.
Outputs explained
- Logarithm value — the computed result, log_b(x). For example, log_2(8) = 3.
- Verification — the calculator shows b^result and confirms it equals x (within rounding), providing a sanity check.
- Equivalent expressions — for convenience, the result is also shown in the other two common bases. For example, if you compute log_2(8) = 3, it also shows log_10(8) = 0.9031 and ln(8) = 2.0794.
- Inverse — the calculator shows b^y = x as the equivalent exponential form, reinforcing the relationship between logarithms and exponents.
Assumptions & limitations
- Positive arguments only — log_b(x) is defined only for x > 0 in the real number system. The calculator returns an error for zero or negative inputs.
- Base restrictions — the base must be positive and not equal to 1. A base of 1 would make the logarithm undefined (since 1^y = 1 for all y, no power of 1 can produce any value other than 1).
- Floating-point precision — results are accurate to approximately 15 significant digits. For values very close to 1, the result will be very close to 0, and small rounding differences may appear.
- Very large or small arguments — arguments larger than approximately 10^308 or smaller than 10^(-308) exceed JavaScript’s floating-point range and will produce Infinity or -Infinity respectively.
- No complex logarithms — the logarithm of a negative number (e.g., log(-1) = i*pi) is a complex number and is not computed by this calculator. Use a complex number calculator for such cases.