Logarithmic Functions: Exponents in Reverse

A complete, plain-language guide with worked examples, diagrams, tables and links to AI and machine learning

In this article
  1. Introduction
  2. What is a logarithm?
  3. Common bases
  4. Laws of logarithms
  5. The graph of a logarithm
  6. Solving equations with logarithms
  7. Logarithmic scales
  8. Time, growth and digits
  9. AI and machine learning
  10. Common mistakes
  11. Practice problems
  12. 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.

The statement 2 cubed equals 8 rewritten as log base 2 of 8 equals 3
Exponential form and logarithmic form are the same fact.

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.

Translating between the two forms
Exponential formLogarithmic formValue
2³ = 8log₂ 8 = 33
10² = 100log₁₀ 100 = 22
5⁰ = 1log₅ 1 = 00
2⁻² = 1/4log₂(1/4) = −2−2
9^(1/2) = 3log₉ 3 = 1/20.5
e¹ = eln e = 11
Values of log₂ x
xWhylog₂ x
1/22^-1 = 1/2-1
12^0 = 10
22^1 = 21
42^2 = 42
82^3 = 83
162^4 = 164

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.

The three common bases
NameNotationExampleTypical use
Commonlog₁₀ xlog₁₀ 1000 = 3pH, decibels, earthquake scales
Naturalln xln e² = 2calculus, growth, ML loss functions
Binarylog₂ xlog₂ 1024 = 10bits, 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.

Bars of length log 20 and log 50 laid end to end equal the bar for log 1000
Adding the lengths of log 20 and log 50 gives the length of log 1000.
The laws of logarithms
LawRuleExample
Productlog_b(xy) = log_b x + log_b ylog₂(8 · 4) = 3 + 2 = 5
Quotientlog_b(x/y) = log_b x − log_b ylog₁₀(1000/10) = 3 − 1 = 2
Powerlog_b(xⁿ) = n · log_b xlog₂(8²) = 2 · 3 = 6
Change of baselog_b x = ln x / ln blog₂ 10 ≈ 3.322
Log of 1log_b 1 = 0log₇ 1 = 0
Log of the baselog_b b = 1log₇ 7 = 1
Cancellingb^(log_b x) = x and log_b(bˣ) = x10^(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.

Expanding and condensing
ExpressionDirectionResult
log₂(8x)expandlog₂ 8 + log₂ x = 3 + log₂ x
ln(e⁵ / x)expand5 − ln x
2 log 3 + log 4condenselog(9 · 4) = log 36
log 50 − log 5condenselog 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.

Graphs of log base 2, natural log and log base 10
Three logarithms share a shape and cross the x-axis at 1.
Properties of y = log_b x (with b > 1)
PropertyValue
Domainx > 0
Rangeall real numbers
x-intercept(1, 0)
Vertical asymptotex = 0
Behaviourincreasing, 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.

Graphs of 2 to the x and log base 2 of x mirrored across y equals x
Swapping inputs and outputs reflects the exponential into the logarithm.
Matching pairs on y = 2ˣ and y = log₂ x
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.

Solving 5ˣ = 20 step by step
StepWork
Start5ˣ = 20
Take ln of both sidesln(5ˣ) = ln 20
Bring the exponent downx · ln 5 = ln 20
Dividex = ln 20 / ln 5
Computex ≈ 1.861
Check5^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 types and methods
EquationMethodSolution
log₃ x = 4convert to exponential formx = 81
2ˣ = 1000take logs of both sidesx = log₂ 1000 ≈ 9.966
5ˣ = 20take logs of both sidesx ≈ 1.861
log x + log(x − 3) = 1combine, solve, then check domainx = 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.

Number line with 1, 10, 100, 1000 and 10000, linear above and logarithmic below
The same five numbers on a linear scale and on a logarithmic scale.

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.

Three logarithmic scales
ScaleFormulaOne step up means
pH−log₁₀[H⁺]ten times fewer hydrogen ions
Decibels10 log₁₀(I/I₀)10 dB = ten times the intensity
Earthquake magnitudelog₁₀(A/A₀)ten times the ground motion (about 32 times the energy)
Sound intensity ratios on the left and the same levels in decibels on the right
Decibels compress a billion-fold range into 0 to 90.
Decibels versus intensity
Level (dB)Intensity ratio I / I₀Written as
0110^0
301,00010^3
601,000,00010^6
901,000,000,00010^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).

Time for money to grow at 5% a year
Target multipleEquationYears
2×1.05ᵗ = 214.21
3×1.05ᵗ = 322.52
5×1.05ᵗ = 532.99
10×1.05ᵗ = 1047.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.

Counting digits with log₁₀
Nlog₁₀ NDigits = ⌊log₁₀ N⌋ + 1
70.8451
851.9292
9993.0003
12,3454.0915
1,000,0006.0007

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.

Curve of negative natural log of p with example points
Cross-entropy loss falls to zero as the correct answer's probability approaches 1.
Cross-entropy loss for the correct class
Probability pLoss −ln pMeaning
0.90.105confident and right
0.50.693unsure
0.12.303mostly wrong
0.014.605confident and wrong
0.0016.908badly 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.

Product versus sum of logs for n events of probability 0.5
Events nProduct 0.5ⁿSum of logs n · ln 0.5
109.77e-04-6.93
1007.89e-31-69.31
10009.33e-302-693.15
20000 (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.

Entropy in bits
DistributionEntropy (bits)
fair coin: 0.5, 0.51.000
biased coin: 0.9, 0.10.469
fair die: 1/6 each2.585
certain event: 10.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.

Curve of the logit function with points at p equal to 0.1, 0.5 and 0.9
The logit maps probabilities from 0 to 1 onto the whole number line.

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.

Candidates remaining after each halving step on a logarithmic axis
Each halving cuts the work in half, so a million items need about 20 steps.
Binary search steps
Items nlog₂ nSteps needed (rounded up)
1,0009.9710
1,000,00019.9320
1,000,000,00029.9030

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.

The same ideas, two vocabularies
AlgebraMachine learning
−ln pcross-entropy or negative log-likelihood loss
log of a product = sum of logslog-likelihood, numerical stability
log₂ and halvingbits, entropy, O(log n) search
inverse of sigmoidlogit
log scalelearning-rate search, log-transformed features
domain x > 0probabilities must be positive

10. Common mistakes

Frequent mistakes and corrections
MistakeWrongRight
Splitting a log of a sumlog(x + y) = log x + log yno such rule; log(xy) = log x + log y
Mixing up quotient and differencelog(x/y) = log x / log ylog(x/y) = log x − log y
Dropping the power rulelog(x³) = (log x)³log(x³) = 3 log x
Taking the log of a non-positive numberlog(−5)undefined for real numbers
Forgetting to check the domainkeeping x = −2reject, since log(−2) does not exist
Mixing baseslog₂ 8 = 8log₂ 8 = 3

11. Practice problems

Try these before looking at the answers.

  1. Evaluate log₂ 32, log₁₀ 0.001 and ln 1.
  2. Write 4³ = 64 in logarithmic form.
  3. Simplify log 4 + log 25.
  4. Solve log₅ x = 3.
  5. Solve 2ˣ = 50, giving the answer to 2 decimal places.
  6. How many digits does 7⁵⁰ have? (Use log₁₀ 7 ≈ 0.8451.)
  7. A model gives probability 0.25 to the correct class. What is the cross-entropy loss −ln p?
  8. How many steps does binary search need for 1,000 items?

Answers.

  1. log₂ 32 = 5, log₁₀ 0.001 = −3, ln 1 = 0.
  2. log₄ 64 = 3.
  3. log(4 · 25) = log 100 = 2.
  4. x = 5³ = 125.
  5. x = ln 50 / ln 2 ≈ 5.64.
  6. log₁₀ 7⁵⁰ = 50 × 0.8451 = 42.255, so 7⁵⁰ has 43 digits.
  7. −ln 0.25 ≈ 1.386.
  8. 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.