Skip to main content

Logarithms: the exponent as the answer

A logarithm answers one question: to what power must the base be raised to give this number? Meet the logarithm as the inverse of the exponential, derive its product, quotient and power laws and the change-of-base formula, and find the doubling time of 5 percent growth exactly.
M01.4.3L0 Foundation25 minIn review

Before this lesson

M01.4.2 Exponential growth and decay M01.3.4 Chaining and undoing: composition and inverse

After this lesson you can

  • Convert between a statement about a power and a statement about a logarithm, and evaluate simple logarithms by hand.
  • Explain the logarithm as the inverse function of the exponential, and sketch its graph as the mirror image.
  • Derive the product, quotient and power laws of logarithms and the change-of-base formula from the rules of powers.
  • Solve for an unknown exponent with logarithms, such as the doubling time of 5 percent growth.

In review. The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.

The question

Money, users or bacteria grow by 5% a step. How many steps until they double? The table of the last lesson says somewhere between 14 and 15. To find the answer exactly we must solve \({1.05^t = 2}\), where the unknown is the exponent itself, and none of the moves of M01.1.3 (adding to, multiplying or dividing both sides) can bring \(t\) down. The tool that can is the logarithm.

From the last lesson

1. For \({f(x) = 5 \times 0.8^x}\), what are the starting value and the growth factor, and is this growth or decay?

Show answer

The starting value is 5 and the factor is 0.8. The factor lies between 0 and 1, so it is decay.

2. What number does \({(1 + \frac1n)^n}\) settle towards as \(n\) grows, and what is it called?

Show answer

About 2.7183. It is called \(e\).

Intuition

Lesson M01.4.1 drew the powers of 2 as a ladder. Read it downwards and it is the exponential: start with an exponent, raise 2 to that power, and out comes a value. The exponent 3 gives \({2^3 = 8}\). Now read it upwards. Start with the value 8 and ask: which exponent made it? The answer, 3, is called the logarithm of 8 to base 2, written \({\log_2 8 = 3}\).

Two rows of numbers in eleven columns. The top row, in blue and labelled exponent, reads 0 to 10. The bottom row, in vermillion and labelled value, reads 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024. The column holding 3 and 8 is highlighted in yellow, with a green arrow down labelled 2 to the x and a green arrow up labelled log base 2. Above, a green note reads read down: raise 2 to the power. Below: read up: log base 2 of 8 equals 3, because 2 cubed equals 8; and the logarithm answers: which exponent?
M01.4.3-F1

The doubling ladder read both ways. Downwards, \(2^x\) turns an exponent into a value. Upwards, the logarithm \(\log_2\) turns a value back into the exponent that made it.

So a logarithm is an exponent. Some more, read off the ladder or a power you know: \({\log_2 1024 = 10}\), because \({2^{10} = 1024}\); \({\log_{10} 1000 = 3}\), because \({10^3 = 1000}\); and \({\log_2 \tfrac12 = -1}\), because \({2^{-1} = \tfrac12}\).

The values between the rungs have logarithms too. The number 1000 lies between \({2^9 = 512}\) and \({2^{10} = 1024}\), so \(\log_2 1000\) lies between 9 and 10; it is about 9.9658. A logarithm is a whole number only when the value sits exactly on a rung.

Build it up

Step 1. The question, written down. \(\log_b x\) is read “log to base \(b\) of \(x\)”, and it asks: \(b\) to what power gives \(x\)? So the two statements below say the same thing, one about a power and one about a logarithm:

\[ \log_b x = y \quad\text{means}\quad b^y = x . \]

Step 2. A machine run backwards. The exponential \(2^x\) is a machine that takes an exponent and gives a value. It never gives the same value twice, because it always increases. So, by M01.3.4, it has an inverse machine that undoes it, and that inverse is \(\log_2\). Running one machine and then the other brings back what went in:

\[ \begin{aligned} \log_2\left(2^x\right) &= x, \\ 2^{\log_2 x} &= x . \end{aligned} \]

The graph of an inverse is the graph of the function reflected in the line \({y = x}\) (M01.3.4), because every point \((a, c)\) of one graph becomes the point \((c, a)\) of the other.

A coordinate grid from minus 2.6 to 8.8 on both axes, with a dashed grey line y equals x labelled mirror. A sky-blue curve y equals 2 to the x rises steeply from the left through (0, 1), (2, 4) and (3, 8). A vermillion curve y equals log base 2 of x rises slowly through (1, 0), (4, 2) and (8, 3), and plunges downwards as x approaches 0. Dotted green segments join each blue point to its mirror point: (3, 8) to (8, 3), (2, 4) to (4, 2), (0, 1) to (1, 0) and (minus 1, one half) to (one half, minus 1). A note at the low end of the vermillion curve reads below 0 for x under 1.
M01.4.3-F2

The logarithm’s graph is the exponential’s graph reflected in the line \({y = x}\): the point \((3, 8)\) of \(2^x\) becomes the point \((8, 3)\) of \(\log_2 x\).

Step 3. Which numbers have a logarithm. Every power of a positive base is positive (M01.4.2), so no exponent turns \(b\) into 0 or into a negative number. Only positive numbers have logarithms. For a base bigger than 1, which covers every logarithm in this module, the logarithm is negative between 0 and 1, as the left end of the vermillion curve shows: \({\log_2 0.5 = -1}\) and \({\log_{10} 0.001 = -3}\). And because \({b^0 = 1}\) and \({b^1 = b}\), every base has

\[ \log_b 1 = 0, \qquad \log_b b = 1 . \]

Step 4. Three everyday bases.

  • The natural logarithm \(\ln x\) is the logarithm to base \(e\), the inverse of \(e^x\). It is the one machine learning uses by default, and it is the one Python’s math.log computes.
  • \(\log_2 x\) counts doublings and halvings, which is why it measures information in bits.
  • \(\log_{10} x\) counts factors of ten, which is why it is linked to the number of digits.

This course always writes the base, except for \(\ln\). Machine-learning papers and most code write “log” with no base, and they mean \(\ln\).

The formal statement

NoteDefinition: logarithm

For a base \({b > 0}\) with \({b \neq 1}\) and a number \({x > 0}\), the logarithm of \(x\) to base \(b\), \(\log_b x\), is the exponent \(y\) for which \({b^y = x}\). The natural logarithm is \({\ln x = \log_e x}\).

Each rule of powers in M01.4.1 has a matching law of logarithms. To derive them, take two positive numbers \(u\) and \(v\) and name their logarithms:

\[ \begin{aligned} m &= \log_b u, & \text{so } u &= b^m, \\ n &= \log_b v, & \text{so } v &= b^n . \end{aligned} \]

The product law. Multiply \(u\) and \(v\) and use the product rule of powers:

\[ uv = b^m\, b^n = b^{m+n} . \]

So the exponent that turns \(b\) into \(uv\) is \({m + n}\), which is what the definition calls \(\log_b(uv)\):

\[ \log_b(uv) = \log_b u + \log_b v . \]

The quotient law. Divide instead, and use the quotient rule:

\[ \frac{u}{v} = \frac{b^m}{b^n} = b^{m-n} . \]

So the exponent that turns \(b\) into \(u / v\) is \({m - n}\):

\[ \log_b\frac{u}{v} = \log_b u - \log_b v . \]

The power law. Raise \(u\) to any power \(k\) and use the power-of-a-power rule: \({u^k = (b^m)^k = b^{mk}}\). So the exponent is \(k\) times \(m\):

\[ \log_b\left(u^k\right) = k \log_b u . \]

The change-of-base formula. Let \({y = \log_b x}\), so that \({b^y = x}\). Take the logarithm to some other base \(c\) of both sides; they are equal numbers, so their logarithms are equal. Then use the power law on the left and divide by \(\log_c b\):

\[ \begin{aligned} \log_c\left(b^y\right) &= \log_c x \\ y \log_c b &= \log_c x \\ y &= \frac{\log_c x}{\log_c b} . \end{aligned} \]

With \({c = e}\) this reads \({\log_b x = \frac{\ln x}{\ln b}}\): knowing \(\ln\) is enough to find every logarithm, and that is exactly how math.log(x, b) works.

Go deeper: logarithms count digits

A positive whole number \(x\) with \(d\) digits is at least \({10^{d-1}}\) and less than \(10^d\), so its logarithm to base 10 is at least \({d - 1}\) and less than \(d\). Its number of digits is therefore the whole part of \(\log_{10} x\), plus 1. For example \(2^{100}\) has \(\log_{10} 2^{100} = 100 \log_{10} 2 \approx 30.103\) by the power law, so it has 31 digits, which the code below confirms without writing the number out by hand.

Worked example

Part 1: find \(\log_2 1024\) by counting halvings. The logarithm asks how many factors of 2 multiply to make 1024. So divide by 2 until 1 is left, and count the divisions.

Eleven boxes in two rows joined by green arrows, each arrow marked divided by 2 and numbered in a yellow badge. Top row: a blue box 1024, then vermillion boxes 512, 256, 128, 64 and 32, with badges 1 to 5. An elbow arrow, badge 6, leads from 32 down to the second row: 16, 8, 4, 2 and a yellow box 1, with badges 7 to 10. Beside the last box: 10 halvings, so log base 2 of 1024 equals 10.
M01.4.3-F3

Counting halvings. Ten halvings take 1024 down to 1, so \({1024 = 2^{10}}\) and \({\log_2 1024 = 10}\).

The halvings are 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1: ten of them. So 1024 is ten factors of 2, \({1024 = 2^{10}}\), and \({\log_2 1024 = 10}\). Each halving is one step down the ladder of the intuition figure.

Part 2: the doubling time of 5% growth. Solve \({1.05^t = 2}\). Both sides are the same number, so they have the same natural logarithm. The power law brings the exponent down, and one division finishes:

\[ \begin{aligned} 1.05^t &= 2 \\ \ln\left(1.05^t\right) &= \ln 2 \\ t \ln 1.05 &= \ln 2 \\ t &= \frac{\ln 2}{\ln 1.05} . \end{aligned} \]

Here \({\ln 2 \approx 0.6931}\) and \({\ln 1.05 \approx 0.0488}\). A calculator divides the unrounded values and gives \({t \approx 14.2067}\), so about 14.21 steps. (Dividing the rounded values gives 14.20: round only at the end.)

A plot of 1.05 to the t against step t from 0 to 20. Vermillion dots at whole steps lie on a rising curve from 1 to about 2.65. A dashed black line at height 2 is labelled double the start: 2. The curve crosses it at a yellow dot, from which a green vertical line drops to the axis, labelled t equals ln 2 over ln 1.05, approximately 14.21. Pointers mark the dots at t equals 14, value 1.9799, just below the line, and t equals 15, value 2.0789, just above it.
M01.4.3-F4

The doubling time read off exactly. The table only says “between 14 and 15”; the logarithm says where: \({t = \ln 2 / \ln 1.05 \approx 14.21}\).

Check. The table of M01.4.2 has \({1.05^{14} \approx 1.9799}\), just short of 2, and \({1.05^{15} \approx 2.0789}\), just past it. The answer 14.21 lies between, as it must. The base of the logarithm does not matter: with base 10, \({\log_{10} 2 \approx 0.3010}\) and \({\log_{10} 1.05 \approx 0.0212}\), and the ratio of the unrounded values is 14.21 again, which is the change-of-base formula at work.

Code

A whole-number logarithm by repeated division, exactly as in Part 1 of the worked example:

def whole_log(x, b):
    """How many times x can be divided by b with the result still at least 1, for x of 1 or more."""
    count = 0
    while x >= b:          # while one more division still leaves at least 1 ...
        x = x / b          # ... divide by the base
        count = count + 1  # and count the division
    return count

print(whole_log(1024, 2), whole_log(1000, 10), whole_log(1000, 2))   # 10 3 9
10 3 9

For 1000 to base 2 the answer 9 is only the whole part: nine halvings leave about 1.95. To find the rest of the exponent, use the fact that \(b^y\) grows as \(y\) grows (for \({b > 1}\)). Keep an interval that holds the answer and halve it again and again: if \(b\) to the middle of the interval is too small, the answer lies in the upper half; otherwise in the lower half. This is called bisection.

def log_bisect(x, b, steps=60):
    """The logarithm of x (1 or more) to base b (more than 1), by bisection on the exponent."""
    low, high = 0.0, 1.0
    while b ** high < x:       # widen the interval until it holds the answer
        high = high * 2
    for _ in range(steps):     # each pass halves the interval
        mid = (low + high) / 2
        if b ** mid < x:       # too small: the answer is above mid
            low = mid
        else:                  # big enough: the answer is at or below mid
            high = mid
    return (low + high) / 2

print(round(log_bisect(1000, 2), 4))     # 9.9658
print(round(log_bisect(2, 1.05), 4))     # the doubling time: 14.2067
9.9658
14.2067

The library versions. math.log with one argument is the natural logarithm; with a second argument it divides by the logarithm of the base. math.log2 and math.log10 are separate, more accurate functions for the two common bases:

import math

print(math.log(math.e), math.log(2))        # ln e = 1.0, and ln 2
print(math.log2(1024), math.log10(1000))    # 10.0 3.0
print(math.log(2) / math.log(1.05))         # change of base, by hand
print(math.log(2, 1.05))                    # the same, with the base given
print(len(str(2 ** 100)), math.floor(100 * math.log10(2)) + 1)   # 31 digits, two ways
1.0 0.6931471805599453
10.0 3.0
14.206699082890461
14.206699082890461
31 31

Why prefer math.log10(1000) to math.log(1000, 10)? The second divides two rounded numbers, and on many machines it prints 2.9999999999999996 instead of 3. The documentation says log2 and log10 are usually more accurate than the two-argument form.

Explore

This module’s interactive, the log ruler, lives in lesson M01.4.4. Its slide rule is the product law of this lesson turned into lengths: laying \(\log_{10} a\) and \(\log_{10} b\) end to end lands on \(\log_{10}(ab)\).

Pitfalls

Two panels, each with a ruler marked 0 to 6 in blue above and 1, 2, 4, 8, 16, 32, 64 in vermillion below, and above it two bars laid end to end, a blue one from 0 to 3 and a sky-blue one from 3 to 6, each labelled log base 2 of 8 equals 3. Left, marked with a cross and titled log base 2 of 8 plus 8 equals 3 plus 3: a reddish-purple ring marks 16 at position 4, with the note 8 plus 8 equals 16 sits at 4, not at 3 plus 3, and log base 2 of 8 plus 8 equals 4. Right, marked with a tick and titled log base 2 of 8 times 8 equals 3 plus 3: a vermillion ring marks 64 at position 6, with the note end to end they reach 6, the place of 64, and log base 2 of 8 times 8 equals 6.
M01.4.3-F5

Wrong beside right. Two lengths of 3 laid end to end reach 6, which is the place of \(64 = 8 \times 8\), not of \(16 = 8 + 8\). Logarithms add when numbers multiply.

“\({\log_2(8 + 8) = \log_2 8 + \log_2 8}\).”

The product law turns a product into a sum. There is no law for the logarithm of a sum. Here the left side is \(\log_2 16\), which is 4, while the right side is \({3 + 3 = 6}\), which is \(\log_2 64\), the logarithm of \({8 \times 8}\).

“math.log(x) is the logarithm to base 10.”

In Python, math.log and numpy.log are the natural logarithm \(\ln\). For base 10 use math.log10, for base 2 math.log2, and for any other base math.log(x, b). Papers in machine learning also write “log” for \(\ln\).

“The logarithm of a small number is a small positive number.”

With base 2, 10 or \(e\), the logarithm is negative below 1: \({\log_{10} 0.001 = -3}\) and \({\ln 0.5 \approx -0.6931}\). At 0 there is no logarithm at all, and math.log(0) stops with an error (ValueError). This matters in lesson M01.4.4, where the logarithms of probabilities are all negative.

“\(\log_b u / \log_b v\) is \(\log_b(u / v)\).”

The logarithm of a quotient is a difference, not a quotient. A quotient of two logarithms is a change of base instead. For example, \(\log_2 8\) divided by \(\log_2 4\) is \(\frac32\), which is \(\log_4 8\) (since \({4^{3/2} = 8}\)), while \(\log_2(8 / 4)\) is 1.

Check yourself

Recall

1. Write \({\log_3 81 = 4}\) as a statement about a power.

Show answer

\({3^4 = 81}\).

2. What are \(\log_{10} 1\), \(\log_{10} 10\) and \(\log_{10} 0.01\)?

Show answer

0, 1 and \({-2}\), because \({10^0 = 1}\), \({10^1 = 10}\) and \({10^{-2} = 0.01}\).

3. State the product law of logarithms and the rule of powers it comes from.

Show answer

\({\log_b(uv) = \log_b u + \log_b v}\). It comes from the product rule \({b^m\, b^n = b^{m+n}}\).

4. Which Python function gives \(\ln x\), and which gives \(\log_{10} x\)?

Show answer

math.log(x) gives \(\ln x\); math.log10(x) gives \(\log_{10} x\).

5. Why is \({\log_2(-4)}\) not defined?

Show answer

Every power of 2 is positive, so no exponent \(y\) makes \({2^y = -4}\).

Exercises

1. ★ Evaluate \(\log_2 32\), \(\log_{10} 100{,}000\), \(\log_5 \frac{1}{25}\) and \(\ln e^3\).

Show solution

Each asks for an exponent. \({2^5 = 32}\), so \({\log_2 32 = 5}\). \({10^5 = 100{,}000}\), so the second is 5. \({5^{-2} = \frac{1}{25}}\), so the third is \({-2}\). And \({\ln e^3 = 3}\), because \(\ln\) undoes \(e^x\).

2. ★★ Use the laws to write each as a single logarithm, then evaluate it: \({\log_2 40 - \log_2 5}\), and \({3 \log_{10} 2 + \log_{10} 125}\).

Show solution

(a) By the quotient law,

\[ \begin{aligned} &\log_2 40 - \log_2 5 \\ &\quad= \log_2 \tfrac{40}{5} = \log_2 8 = 3 . \end{aligned} \]

(b) The power law turns \(3 \log_{10} 2\) into \({\log_{10} 2^3 = \log_{10} 8}\). Then the product law gives

\[ \begin{aligned} &\log_{10} 8 + \log_{10} 125 \\ &\quad= \log_{10}(8 \times 125) \\ &\quad= \log_{10} 1000 = 3 . \end{aligned} \]

3. ★★★ In lesson M01.4.2 a learning rate of 0.1 was multiplied by 0.9 every epoch, and a table showed that it first falls below 0.01 after 22 epochs. Solve \({0.1 \times 0.9^t = 0.01}\) exactly, and explain how your answer agrees with the table. Then find the half-life the same way.

Show solution

Divide both sides by 0.1, then take natural logarithms and use the power law:

\[ \begin{aligned} 0.9^t &= 0.1 \\ t \ln 0.9 &= \ln 0.1 \\ t &= \frac{\ln 0.1}{\ln 0.9} \approx 21.85 . \end{aligned} \]

Both logarithms are negative, so their ratio is positive. The rate equals 0.01 after 21.85 epochs, between whole epochs 21 and 22, so the first whole epoch with a rate below 0.01 is epoch 22, as the table said. For the half-life, solve \({0.9^t = 0.5}\) in the same way:

\[ t = \frac{\ln 0.5}{\ln 0.9} \approx 6.58 \text{ epochs}, \]

between 6 and 7, again as the table said.

Summary card

A logarithm is an exponent: \(\log_b x\) is the power that turns \(b\) into \(x\).

The anchor figure again: the exponents 0 to 10 above the values 1 to 1024, with arrows down for 2 to the x and up for log base 2 in the column of 3 and 8.
M01.4.3-F1

Read the ladder upwards.

\[ \begin{aligned} \log_b x = y \;&\Longleftrightarrow\; b^y = x \\ \log_b(uv) &= \log_b u + \log_b v \\ \log_b(u/v) &= \log_b u - \log_b v \\ \log_b(u^k) &= k \log_b u \\ \log_b x &= \ln x / \ln b \end{aligned} \]

  • Doubling time of growth at rate \(r\): \({\ln 2 / \ln(1 + r)}\); for 5% it is 14.21 steps.
  • In Python, math.log is \(\ln\); use math.log2 and math.log10 for bases 2 and 10.

Sources and next steps

Sources. Each was opened and checked against this lesson on 12 November 2026.

  • Jay Abramson and others, Algebra and Trigonometry 2e, OpenStax. Section 6.3, Logarithmic Functions: \({y = \log_b x}\) exactly when \({b^y = x}\), for \({x > 0}\), \({b > 0}\) and \({b \neq 1}\), with the common logarithm (base 10) and the natural logarithm \(\ln\) (base \(e\)). Section 6.4: the graphs of \(\log_b x\) and \(b^x\) are reflections of each other across \({y = x}\), with domain \((0, \infty)\) and the point \((1, 0)\). Section 6.5, Logarithmic Properties: the product, quotient and power rules, the product rule derived from the product rule for exponents, and the change-of-base formula.
  • Python Software Foundation, the math module, Python 3.12 documentation. log(x) is the natural logarithm and log(x, base) is calculated as log(x)/log(base); log2 and log10 are usually more accurate than log(x, 2) and log(x, 10); and log(0.0) raises ValueError.
  • Daniel Jurafsky and James H. Martin, Speech and Language Processing, 3rd edition draft of 19 August 2026, Chapter 3, Section 3.7: with the logarithm to base 2, entropy, a measure of information, is measured in bits, and a choice among eight equally likely options takes \({-\log_2 \tfrac18 = 3}\) bits (Equation 3.34).

Next. M01.4.4 Log scales and why machine learning takes logs turns the logarithm into a ruler, and the product law into a cure for vanishing products.

This lesson unlocks

M01.4.4 Log scales and why machine learning takes logs M01.7.4 Products and double sums

Your progress is saved in this browser only. No account, no tracking.
Back to top