- Introduction
- What is a logarithm?
- Common bases
- Laws of logarithms
- The graph of a logarithm
- Solving equations with logarithms
- Logarithmic scales
- Time, growth and digits
- AI and machine learning
- Common mistakes
- Practice problems
- Conclusion
1. Introduction
Exponentials answer the question "what do I get if I multiply by this factor again and again?" Logarithms ask the reverse: "how many times did I have to multiply?" If a bacterial colony has grown to 1,024 times its original size by doubling, the logarithm tells you it doubled 10 times. A logarithm is, quite literally, an exponent in disguise.
That reverse question turns out to be extremely useful. Logarithms let us solve equations where the unknown sits in an exponent, turn products into sums, and squeeze numbers that range from tiny to astronomical onto a readable scale. Earthquakes, sound, acidity and information are all measured this way.
This article defines logarithms, shows the common bases, builds the laws that make them powerful, and applies them to equations, scales, growth and digits. We finish with the place logarithms occupy in machine learning, where the most common loss function is a logarithm.
2. What is a logarithm?
The logarithm of a number x to the base b is the exponent you must raise b to in order to get x. In symbols, log_b(x) = y means exactly the same as bʸ = x. The two statements are one fact written two ways.
Read log₂ 8 as "2 to what power gives 8?" The answer is 3, since 2³ = 8. The base must be positive and not equal to 1, and the number inside must be positive, because no power of a positive base can give zero or a negative number.
| Exponential form | Logarithmic form | Value |
|---|---|---|
| 2³ = 8 | log₂ 8 = 3 | 3 |
| 10² = 100 | log₁₀ 100 = 2 | 2 |
| 5⁰ = 1 | log₅ 1 = 0 | 0 |
| 2⁻² = 1/4 | log₂(1/4) = −2 | −2 |
| 9^(1/2) = 3 | log₉ 3 = 1/2 | 0.5 |
| e¹ = e | ln e = 1 | 1 |
| x | Why | log₂ x |
|---|---|---|
| 1/2 | 2^-1 = 1/2 | -1 |
| 1 | 2^0 = 1 | 0 |
| 2 | 2^1 = 2 | 1 |
| 4 | 2^2 = 4 | 2 |
| 8 | 2^3 = 8 | 3 |
| 16 | 2^4 = 16 | 4 |
Because logarithms and exponentials undo each other, each one cancels the other. Raising the base to a logarithm returns the number, and taking the logarithm of a power returns the exponent.
3. Common bases
Three bases dominate. The common logarithm uses base 10 and is written log x or log₁₀ x. It counts powers of ten and is the standard in measurement scales. The natural logarithm uses the number e ≈ 2.718 and is written ln x. It is the inverse of eˣ and the standard in calculus, statistics and machine learning. The binary logarithm uses base 2, is written log₂ x, and is the standard in computing and information theory.
| Name | Notation | Example | Typical use |
|---|---|---|---|
| Common | log₁₀ x | log₁₀ 1000 = 3 | pH, decibels, earthquake scales |
| Natural | ln x | ln e² = 2 | calculus, growth, ML loss functions |
| Binary | log₂ x | log₂ 1024 = 10 | bits, search, computer science |
Calculators usually offer only log and ln. Any other base can be reached by the change-of-base formula: log_b x = ln x / ln b. For instance log₂ 10 = ln 10 / ln 2 ≈ 3.322, meaning 2 must be raised to about the power 3.32 to reach 10.
4. Laws of logarithms
The reason logarithms transformed science before computers is that they turn multiplication into addition. Since exponents add when powers are multiplied, logarithms add when numbers are multiplied: log_b(xy) = log_b x + log_b y. Slide rules, used by engineers for centuries, were rulers marked in logarithms so that sliding two lengths together added them and performed a multiplication.
| Law | Rule | Example |
|---|---|---|
| Product | log_b(xy) = log_b x + log_b y | log₂(8 · 4) = 3 + 2 = 5 |
| Quotient | log_b(x/y) = log_b x − log_b y | log₁₀(1000/10) = 3 − 1 = 2 |
| Power | log_b(xⁿ) = n · log_b x | log₂(8²) = 2 · 3 = 6 |
| Change of base | log_b x = ln x / ln b | log₂ 10 ≈ 3.322 |
| Log of 1 | log_b 1 = 0 | log₇ 1 = 0 |
| Log of the base | log_b b = 1 | log₇ 7 = 1 |
| Cancelling | b^(log_b x) = x and log_b(bˣ) = x | 10^(log 50) = 50 |
The power law is the one that rescues equations with unknown exponents: it lets you bring the exponent down in front. Notice what the laws do not say. There is no rule for the logarithm of a sum, so log(x + y) cannot be split into log x + log y.
The laws can be used in both directions. Expanding breaks one logarithm into simpler pieces: log(x²y / z) = 2 log x + log y − log z. Condensing does the reverse, combining pieces into one: 3 log 2 + log 5 − log 10 becomes log(2³ · 5 / 10) = log 4. Condensing is exactly the move used to solve many logarithmic equations, as we will see.
| Expression | Direction | Result |
|---|---|---|
| log₂(8x) | expand | log₂ 8 + log₂ x = 3 + log₂ x |
| ln(e⁵ / x) | expand | 5 − ln x |
| 2 log 3 + log 4 | condense | log(9 · 4) = log 36 |
| log 50 − log 5 | condense | log 10 = 1 |
5. The graph of a logarithm
The graph of y = log_b x has a distinctive shape. It rises steeply at first, then flattens and keeps climbing ever more slowly. It passes through (1, 0) since log_b 1 = 0, has a vertical asymptote at x = 0, and is defined only for x > 0.
| Property | Value |
|---|---|
| Domain | x > 0 |
| Range | all real numbers |
| x-intercept | (1, 0) |
| Vertical asymptote | x = 0 |
| Behaviour | increasing, but ever more slowly |
| Passes through | (b, 1) |
Since a logarithm undoes an exponential, its graph is the exponential graph reflected across the line y = x. Every point (a, b) on y = 2ˣ becomes (b, a) on y = log₂ x. The exponential's horizontal asymptote y = 0 becomes the logarithm's vertical asymptote x = 0, and where exponentials explode, logarithms crawl.
| On y = 2ˣ | On y = log₂ x |
|---|---|
| (1, 2) | (2, 1) |
| (3, 8) | (8, 3) |
| (0, 1) | (1, 0) |
| (−1, 1/2) | (1/2, −1) |
6. Solving equations with logarithms
The first kind of equation has the unknown inside a logarithm. Convert to exponential form and solve. For log₃ x = 4, the equation means 3⁴ = x, so x = 81. For log₂(x + 1) = 3, we get x + 1 = 8, so x = 7.
The second kind has the unknown in an exponent, which could not be solved last time unless the bases matched. Take the logarithm of both sides, bring the exponent down with the power law, and divide. To solve 5ˣ = 20, write x · ln 5 = ln 20, so x = ln 20 / ln 5 ≈ 1.861. This is sensible, since 5¹ = 5 and 5² = 25 bracket 20.
| Step | Work |
|---|---|
| Start | 5ˣ = 20 |
| Take ln of both sides | ln(5ˣ) = ln 20 |
| Bring the exponent down | x · ln 5 = ln 20 |
| Divide | x = ln 20 / ln 5 |
| Compute | x ≈ 1.861 |
| Check | 5^1.861 ≈ 20 |
A harder example: 3^(2x − 1) = 50. Then (2x − 1) ln 3 = ln 50, so 2x − 1 = ln 50 / ln 3 ≈ 3.561, giving 2x ≈ 4.561 and x ≈ 2.280.
Logarithmic equations can have extraneous solutions, answers that the algebra produces but the domain forbids. Solve log x + log(x − 3) = 1. Combine with the product law: log[x(x − 3)] = 1, so x(x − 3) = 10, which is x² − 3x − 10 = 0, or (x − 5)(x + 2) = 0. Both 5 and −2 solve the quadratic. But x = −2 would require log(−2), which does not exist, so only x = 5 is valid. The check works: log 5 + log 2 = log 10 = 1.
| Equation | Method | Solution |
|---|---|---|
| log₃ x = 4 | convert to exponential form | x = 81 |
| 2ˣ = 1000 | take logs of both sides | x = log₂ 1000 ≈ 9.966 |
| 5ˣ = 20 | take logs of both sides | x ≈ 1.861 |
| log x + log(x − 3) = 1 | combine, solve, then check domain | x = 5 (reject −2) |
7. Logarithmic scales
When quantities span huge ranges, logarithms compress them. On a logarithmic scale, each equal step represents multiplication by the same factor rather than addition of the same amount. On a normal number line, 1, 10 and 100 are crowded against zero beside 10,000. On a log line they are evenly spaced, one step per power of ten.
Acidity is measured by pH, defined as pH = −log₁₀[H⁺], where [H⁺] is the hydrogen-ion concentration. Each drop of 1 in pH means ten times more hydrogen ions, so pH 3 is 10⁻³ / 10⁻⁷ = 10,000 times more acidic than neutral pH 7. Sound level in decibels is L = 10 log₁₀(I / I₀). Doubling the intensity adds only 10 log₁₀ 2 ≈ 3.01 dB, and 90 dB is a billion times the reference intensity. Earthquake magnitude works the same way: each whole step is a tenfold increase in measured ground motion, and about 32 times more energy released.
| Scale | Formula | One step up means |
|---|---|---|
| pH | −log₁₀[H⁺] | ten times fewer hydrogen ions |
| Decibels | 10 log₁₀(I/I₀) | 10 dB = ten times the intensity |
| Earthquake magnitude | log₁₀(A/A₀) | ten times the ground motion (about 32 times the energy) |
| Level (dB) | Intensity ratio I / I₀ | Written as |
|---|---|---|
| 0 | 1 | 10^0 |
| 30 | 1,000 | 10^3 |
| 60 | 1,000,000 | 10^6 |
| 90 | 1,000,000,000 | 10^9 |
8. Time, growth and digits
Logarithms answer "how long?" questions about growth. If 1000 dollars grows at 5 percent a year, when does it reach 2,000 dollars? We need 1.05ᵗ = 2, so t = ln 2 / ln 1.05 ≈ 14.21 years. For any target multiple M, the time is t = ln M / ln(1 + r).
| Target multiple | Equation | Years |
|---|---|---|
| 2× | 1.05ᵗ = 2 | 14.21 |
| 3× | 1.05ᵗ = 3 | 22.52 |
| 5× | 1.05ᵗ = 5 | 32.99 |
| 10× | 1.05ᵗ = 10 | 47.19 |
The same method dates ancient material. A sample with 20 percent of its carbon-14 left satisfies 0.5^(t/5730) = 0.2. Taking logs gives t = 5730 · log₂ 5 ≈ 13,305 years, matching the estimate in the previous article.
Logarithms also count digits. A positive whole number N has ⌊log₁₀ N⌋ + 1 digits, where the brackets mean "round down." The base-10 logarithm is essentially the number of zeros after the leading digit, which is why it measures size by powers of ten.
| N | log₁₀ N | Digits = ⌊log₁₀ N⌋ + 1 |
|---|---|---|
| 7 | 0.845 | 1 |
| 85 | 1.929 | 2 |
| 999 | 3.000 | 3 |
| 12,345 | 4.091 | 5 |
| 1,000,000 | 6.000 | 7 |
9. AI and machine learning
The best-known use of logarithms in machine learning is the loss function for classification, cross-entropy. If a model assigns probability p to the correct answer, the loss is −ln p. A confident right answer (p = 0.9) costs only 0.105. A shrug (p = 0.5) costs 0.693. A confident wrong answer (p = 0.01) costs 4.605, and the penalty grows without limit as p approaches 0. That shape pushes models to be both accurate and honest about uncertainty.
| Probability p | Loss −ln p | Meaning |
|---|---|---|
| 0.9 | 0.105 | confident and right |
| 0.5 | 0.693 | unsure |
| 0.1 | 2.303 | mostly wrong |
| 0.01 | 4.605 | confident and wrong |
| 0.001 | 6.908 | badly wrong |
The product law explains why training uses log-likelihood. The probability of many independent events is a product of many numbers below 1, which collapses toward zero. 2,000 events of probability 0.5 each have a combined probability of 0.5²⁰⁰⁰, so small that a computer in standard double precision stores it as exactly 0. Taking logs turns the product into a sum, 2000 · ln 0.5 ≈ −1386.29, a perfectly ordinary number. Maximising the log gives the same answer as maximising the original.
| Events n | Product 0.5ⁿ | Sum of logs n · ln 0.5 |
|---|---|---|
| 10 | 9.77e-04 | -6.93 |
| 100 | 7.89e-31 | -69.31 |
| 1000 | 9.33e-302 | -693.15 |
| 2000 | 0 (underflow) | -1386.29 |
Information theory uses base-2 logs to measure uncertainty in bits. The entropy of a distribution is H = −Σ pᵢ log₂ pᵢ. A fair coin has 1 bit of entropy, a fair six-sided die has log₂ 6 ≈ 2.585 bits, and a coin that lands heads 90 percent of the time has only 0.469 bits, because it is more predictable.
| Distribution | Entropy (bits) |
|---|---|
| fair coin: 0.5, 0.5 | 1.000 |
| biased coin: 0.9, 0.1 | 0.469 |
| fair die: 1/6 each | 2.585 |
| certain event: 1 | 0.000 |
The logit, ln(p / (1 − p)), is the inverse of the sigmoid function from earlier articles. Sigmoid turns any real score into a probability, and the logit turns a probability back into a score, stretching the range 0 to 1 onto the entire number line. A probability of 0.9 corresponds to a logit of 2.197, and σ(2.197) = 0.9.
Logarithms are also behind algorithmic efficiency. Binary search repeatedly halves the candidates, so finding one item among 1,000,000 takes about log₂ 1,000,000 ≈ 20 steps, and among a billion only 30. Algorithms of this kind are labelled O(log n), and the slow growth of the logarithm is exactly why they scale so well.
| Items n | log₂ n | Steps needed (rounded up) |
|---|---|---|
| 1,000 | 9.97 | 10 |
| 1,000,000 | 19.93 | 20 |
| 1,000,000,000 | 29.90 | 30 |
Practical habits follow too. Skewed data such as incomes are often replaced by their logarithm so a few huge values do not dominate. Learning rates are searched on a log scale, trying 10⁻⁵, 10⁻⁴, 10⁻³, 10⁻², 10⁻¹ rather than evenly spaced values, because what matters is the order of magnitude. And log-probabilities replace raw probabilities throughout language models for the stability reasons above.
| Algebra | Machine learning |
|---|---|
| −ln p | cross-entropy or negative log-likelihood loss |
| log of a product = sum of logs | log-likelihood, numerical stability |
| log₂ and halving | bits, entropy, O(log n) search |
| inverse of sigmoid | logit |
| log scale | learning-rate search, log-transformed features |
| domain x > 0 | probabilities must be positive |
10. Common mistakes
| Mistake | Wrong | Right |
|---|---|---|
| Splitting a log of a sum | log(x + y) = log x + log y | no such rule; log(xy) = log x + log y |
| Mixing up quotient and difference | log(x/y) = log x / log y | log(x/y) = log x − log y |
| Dropping the power rule | log(x³) = (log x)³ | log(x³) = 3 log x |
| Taking the log of a non-positive number | log(−5) | undefined for real numbers |
| Forgetting to check the domain | keeping x = −2 | reject, since log(−2) does not exist |
| Mixing bases | log₂ 8 = 8 | log₂ 8 = 3 |
11. Practice problems
Try these before looking at the answers.
- Evaluate log₂ 32, log₁₀ 0.001 and ln 1.
- Write 4³ = 64 in logarithmic form.
- Simplify log 4 + log 25.
- Solve log₅ x = 3.
- Solve 2ˣ = 50, giving the answer to 2 decimal places.
- How many digits does 7⁵⁰ have? (Use log₁₀ 7 ≈ 0.8451.)
- A model gives probability 0.25 to the correct class. What is the cross-entropy loss −ln p?
- How many steps does binary search need for 1,000 items?
Answers.
- log₂ 32 = 5, log₁₀ 0.001 = −3, ln 1 = 0.
- log₄ 64 = 3.
- log(4 · 25) = log 100 = 2.
- x = 5³ = 125.
- x = ln 50 / ln 2 ≈ 5.64.
- log₁₀ 7⁵⁰ = 50 × 0.8451 = 42.255, so 7⁵⁰ has 43 digits.
- −ln 0.25 ≈ 1.386.
- log₂ 1000 ≈ 9.97, so 10 steps.
12. Conclusion
A logarithm is an exponent in disguise: log_b(x) is the power you raise b to in order to get x. Its laws turn multiplication into addition, division into subtraction and powers into multiplication, which is why they solve equations with unknown exponents. The graph is the exponential reflected across y = x, defined only for positive inputs, rising ever more slowly.
Logarithmic scales compress huge ranges into readable ones, as with pH, decibels and earthquakes. In machine learning, logarithms provide the cross-entropy loss, the stable log-likelihood, the entropy of a distribution, the logit and efficient O(log n) algorithms. The next article moves from curves to patterns: sequences and series.