Logarithm Calculator
Compute logarithms in any base including natural log using change-of-base formula.
About the Logarithm Calculator
The logarithm calculator computes log_b(x): the exponent to which the base b must be raised to obtain x. The inverse of exponentiation, logarithms were invented by John Napier in 1614 (Mirifici Logarithmorum Canonis Descriptio) and quickly adopted by astronomers such as Kepler to simplify multiplication and division into addition and subtraction of logs.
Three bases are so common that they have dedicated notation: the natural logarithm ln(x) uses base e (approximately 2.71828), the common logarithm log10(x) uses base 10, and the binary logarithm log2(x) uses base 2. The natural log is the default in calculus because its derivative is 1/x. The common log is used in pH, decibels, and the Richter scale. The binary log appears in information theory (Shannon entropy, bits) and in the analysis of algorithms.
The tool accepts any positive base other than 1 (since log base 1 is undefined: no power of 1 produces any other number). It also accepts any positive x, since the logarithm is undefined for non-positive values. The change-of-base formula log_b(x) = ln(x) / ln(b) is used internally, which means the result has the precision of a single natural-logarithm computation.
The tool reports the natural, common, and binary logarithms alongside your requested base, so you can convert between conventions at a glance. Per ECMA-262 §21.3, Math.log is the natural log, Math.log10 is the common log, and Math.log2 is the binary log.
How It Works
The calculator uses the change-of-base formula to compute any base from the natural logarithm:
log_b(x) = ln(x) / ln(b)
This formula is a direct consequence of the definition: if y = log_b(x), then b^y = x. Taking the natural log of both sides gives y * ln(b) = ln(x), so y = ln(x) / ln(b). The formula works for any positive base b other than 1.
Three special bases have dedicated JavaScript functions for accuracy and convenience:
ln(x) = Math.log(x) (natural log, base e)
log10(x) = Math.log10(x) (common log, base 10)
log2(x) = Math.log2(x) (binary log, base 2)
The tool uses Math.log for the natural log and the change-of-base formula for any other base. For the special bases 10 and 2, it also reports the dedicated Math.log10 and Math.log2 values for cross-checking.
The logarithm is undefined for x less than or equal to zero, because no power of a positive base produces a non-positive result. The tool rejects these inputs explicitly. The base must also be positive and not equal to 1, because log base 1 is undefined (no exponent makes 1^y equal to anything other than 1).
Worked Examples
Using the default values x = 1000 and base = e, the natural log of 1000 is approximately 6.907755. This is because e^6.907755 is approximately 1000. The common log (base 10) of 1000 is exactly 3, since 10^3 = 1000. The binary log (base 2) is approximately 9.965784, since 2^9.965784 is approximately 1000.
For x = 256 and base = 2, the result is exactly 8, since 2^8 = 256. This is a useful fact in computer science: a byte can represent 256 distinct values, which is 2^8 = 256, so a byte is described as "8 bits" because log2(256) = 8.
For x = 0.001 and base = 10, the result is -3, since 10^-3 = 0.001. Negative logarithms indicate values less than 1, because the base must be raised to a negative power to reach a fraction. For x = 1 and any base, the result is 0, because any base raised to the power 0 equals 1.
When to Use This Tool
Use the logarithm calculator when you need to:
- Compute the pH of a solution from its hydrogen ion concentration (pH = -log10[H+]).
- Convert a decibel ratio from a power ratio (dB = 10 * log10(P/P0)).
- Find the number of bits required to represent a value (bits = ceil(log2(n))).
- Compute the half-life of a radioactive substance from its decay constant.
- Analyse the time complexity of a divide-and-conquer algorithm (T(n) = n log n).
- Compute Shannon entropy or information content in bits.
- Convert between logarithmic scales such as pH, decibels, and the Richter scale.
Limitations & Disclaimer
This calculator uses the change-of-base formula with the natural logarithm and is subject to IEEE 754 floating-point precision. Inputs of zero or negative values are rejected as undefined. The base must be positive and not equal to 1. Very large inputs may lose precision; for symbolic or arbitrary-precision logarithms, use a computer algebra system. See our disclaimer for full details.
Frequently Asked Questions
Why is the natural log called natural?
Because its base, e (approximately 2.71828), arises naturally in calculus. The derivative of ln(x) is 1/x, and the integral of 1/x is ln(|x|). No other base has this property without a scaling factor. The constant e was introduced by Jacob Bernoulli in 1683 while studying compound interest; the name e was given by Euler in 1731.
How is log_b(x) related to ln(x)?
By the change-of-base formula: log_b(x) = ln(x) / ln(b). The formula is a direct consequence of the definition of a logarithm. Taking the natural log of both sides of b^y = x gives y * ln(b) = ln(x), so y = ln(x) / ln(b). The formula works for any positive base other than 1.
Why is log(0) undefined?
Because no power of any positive base equals zero. As the exponent approaches negative infinity, b^e approaches zero but never reaches it. The limit of log_b(x) as x approaches zero from above is negative infinity, which is not a finite value. The tool rejects non-positive x inputs explicitly.
What is the difference between log and ln?
In mathematics, log(x) without a base typically means the natural log (base e), especially in calculus. In engineering and chemistry, log(x) often means the common log (base 10). In computer science, log(x) often means the binary log (base 2). The tool reports all three explicitly to avoid ambiguity.
Can the logarithm of a number be negative?
Yes, when the input is between 0 and 1. log10(0.1) = -1, log10(0.01) = -2, and so on. Negative logarithms indicate that the input is a fraction, because the base must be raised to a negative power to produce a value less than 1. A logarithm of zero means the input equals 1, since any base raised to the power 0 is 1.
Why is log base 1 undefined?
Because no power of 1 produces any number other than 1. The function 1^y is constant at 1 for all real y, so it has no inverse. The change-of-base formula confirms this: log_1(x) = ln(x) / ln(1) = ln(x) / 0, which is undefined. The tool rejects base 1 explicitly.
Last updated: September 9, 2026 · Author: HT99 Tools Editorial Team