Sub topic 11
Changing the Base
Prerequisites and goal
This chapter assumes you know the definition of a logarithm, the inverse relationship between logarithms and exponentials, the power law, and the common bases 10, e and 2. You should also be able to run short Python scripts.
Calculators usually have only two logarithm keys: log (base 10) and ln (base e). Python's math module has log2, log10 and log. A problem may still ask for log base 3 of 20, or log base 7 of 50. The change-of-base formula lets you compute a logarithm in any base using a logarithm in a base you already have.
By the end of this chapter you should be able to:
- State the change-of-base formula and derive it.
- Evaluate a logarithm in any valid base with a calculator or code.
- Use the formula to compare logarithms, simplify expressions, and solve equations.
- Avoid the usual errors in applying it.
The formula
For any positive base b ≠ 1, any positive base c ≠ 1, and any x > 0:
logb(x) = logc(x) / log_c(b)
The base c is the new base. You can pick any valid one. The usual choices are 10, e or 2, because those are the bases your tools provide.
With natural logarithms the formula reads:
log_b(x) = ln(x) / ln(b)
The restrictions on b, c and x come straight from the definition of a logarithm. The base must be positive and not equal to 1, and the argument must be positive. The denominator logc(b) is never zero, because b ≠ 1 and logc(b) = 0 only when b = 1.
Why the formula works
The derivation uses only the definition and the power law.
- Let y = log_b(x). By definition, this means b^y = x.
- Take logc of both sides: logc(b^y) = log_c(x).
- Apply the power law to the left side: y · logc(b) = logc(x).
- Divide both sides by logc(b), which is nonzero: y = logc(x) / log_c(b).
Since y was log_b(x), this is the formula.
The power law is what makes the proof work. It moves the unknown exponent y out of the exponent position, so you can solve for it with ordinary algebra.
A worked example
Evaluate log_3(20).
Using natural logarithms:
log_3(20) = ln(20) / ln(3) ≈ 2.9957 / 1.0986 ≈ 2.727
A sanity check is worth doing every time. Since 3² = 9 and 3³ = 27, and 20 lies between 9 and 27, the answer must lie between 2 and 3. The value 2.727 passes. It is also closer to 3 than to 2, which fits because 20 is closer to 27 than to 9.
The same computation in Python:
import math
# Evaluate log base 3 of 20 using natural logarithms
value = math.log(20) / math.log(3)
print(round(value, 3)) # 2.727
print(math.isclose(3 ** value, 20.0)) # TrueThe second line is a round-trip check. If value really is log_3(20), then raising 3 to that power must give back 20. Floating-point arithmetic can leave tiny errors in the last digits, so the code uses math.isclose rather than ==.
Python also lets you pass the base directly: math.log(20, 3). Internally it does the same division. Writing the division yourself shows what is happening and works the same way on a calculator.
The choice of new base does not matter
You can use base 10 or base e and get the same answer, apart from rounding:
log_3(20) = log10(20) / log10(3) ≈ 1.3010 / 0.4771 ≈ 2.727
This works because changing the base only multiplies a logarithm by a constant. For fixed b, the factor 1 / logc(b) does not depend on x. So logarithms in different bases of the same number differ by a fixed scale factor. This is why the graphs of log2(x), ln(x) and log10(x) have the same shape and are only stretched vertically relative to one another.
A useful consequence: when an expression has a ratio of two logarithms with the same new base, you can use any base you like and the result is unchanged. The formula also gives you a way to move between the three common bases:
| Conversion | Formula |
|---|---|
| log_2(x) from ln | ln(x) / ln(2) ≈ 1.4427 · ln(x) |
| log_2(x) from log10 | log10(x) / log10(2) ≈ 3.3219 · log10(x) |
| ln(x) from log10 | log10(x) / log10(e) ≈ 2.3026 · log10(x) |
| log10(x) from ln | ln(x) / ln(10) ≈ 0.4343 · ln(x) |
The reciprocal identity
Setting c = x in the formula gives a neat special case. For x ≠ 1:
logb(x) = logx(x) / logx(b) = 1 / logx(b)
So logb(x) · logx(b) = 1. The two logarithms with the bases and arguments swapped are reciprocals.
For example, log2(8) = 3, and log8(2) = 1/3. You can confirm this: 8^(1/3) = 2.
The condition x ≠ 1 matters because x is being used as a base here. A base of 1 is not allowed.
A chain version
The formula can be applied twice to give a chain:
loga(b) · logb(c) = log_a(c)
Here is the reason. Convert each factor to natural logarithms:
(ln b / ln a) · (ln c / ln b) = ln c / ln a
The ln b terms cancel. This is useful for simplifying products of logarithms with different bases. For instance, log2(3) · log3(4) · log4(5) = log2(5).
Using the formula to simplify and solve
Comparing logarithms in different bases
Which is larger, log2(10) or log3(20)?
Convert both to natural logarithms:
- log_2(10) = ln(10) / ln(2) ≈ 2.3026 / 0.6931 ≈ 3.322
- log_3(20) ≈ 2.727
So log_2(10) is larger. You cannot compare these just by looking at the numbers inside, because the bases differ.
Solving an exponential equation
Change of base often appears when you solve an equation whose unknown is in an exponent and the answer is not a whole number. Solve 5 · 2^x = 80:
- Divide by 5: 2^x = 16.
- Rewrite as a logarithm: x = log_2(16).
- Evaluate: x = 4.
Here 16 is a power of 2, so the answer is a whole number. When it is not, the formula finishes the job. Solve 3^x = 20 and you get x = log_3(20) = ln(20) / ln(3) ≈ 2.727.
The Python check for both cases:
import math
# Solve 5 * 2**x = 80 -> 2**x = 16 -> x = log2(16)
x = math.log2(80 / 5)
print(x) # 4.0
# Solve 3**x = 20 using change of base
x2 = math.log(20) / math.log(3)
print(round(x2, 3)) # 2.727Another way to solve 3^x = 20 is to take ln of both sides directly: x · ln(3) = ln(20). That is the same derivation as in the formula, so the two methods agree.
Evaluating a logarithm with a fractional base
The formula does not require b > 1. Evaluate log_(1/2)(8):
log_(1/2)(8) = ln(8) / ln(1/2) = ln(8) / (−ln 2) = −3
Check: (1/2)^(−3) = 2³ = 8. Bases between 0 and 1 give a negative denominator, so the sign of the result flips compared with the base-2 value.
Edge cases and common errors
- Dividing in the wrong order. The new-base logarithm of the argument goes on top, and the new-base logarithm of the old base goes on the bottom. Check with a case you know: log_2(8) = ln(8) / ln(2) = 3, not ln(2) / ln(8) = 1/3.
- Cancelling the logs. The expression ln(x) / ln(b) is not equal to ln(x / b), and you cannot cancel "ln" from the top and bottom. The ln is a function name, not a factor.
- Mixing bases inside one ratio. Both the numerator and denominator must use the same new base. Writing log10(x) / ln(b) gives a wrong answer.
- Invalid inputs. If x ≤ 0, the logarithm is undefined. If the base b is 1, the denominator ln(1) = 0 and the formula fails. In Python,
math.log(20, 1)raises aZeroDivisionError, andmath.log(-5)raises aValueError. - Rounding too early. If you round ln(20) and ln(3) to two decimals before dividing, you get 3.00 / 1.10 ≈ 2.73, which is noticeably off in the third decimal place. Keep full precision until the last step.
- Floating-point exactness. In code,
math.log(8) / math.log(2)may return3.0000000000000004or2.9999999999999996on some inputs rather than exactly 3. Usemath.isclosefor comparisons, or usemath.log2when the base is 2, which is more accurate for exact powers of two.
import math
print(math.log(1000) / math.log(10)) # may print 2.9999999999999996
print(math.log10(1000)) # 3.0
print(math.isclose(math.log(1000) / math.log(10), 3.0)) # TrueWhere it shows up
Algorithm analysis uses base 2 for halving problems, such as binary search, but a formula may be given in base 10 or e. Because of the constant-factor relationship, log_2(n) and ln(n) differ only by the fixed factor 1.4427. That is why the base is usually left out of big-O notation: O(log n) means the same growth rate in every base.
In the same way, decibels use base 10, and some information measures use base 2 or e. Converting between them uses the factors in the table above.
Exercise
Evaluate log5(100) to three decimal places using natural logarithms, then confirm your result by raising 5 to it. Also state the reciprocal log100(5).
Show answer
log5(100) = ln(100) / ln(5) ≈ 4.6052 / 1.6094 ≈ 2.861. Check: 5^2.861 ≈ 100, which is consistent because 5² = 25 and 5³ = 125 bracket 100, with the answer nearer to 3. The reciprocal is log100(5) = 1 / 2.861 ≈ 0.350.
Exercise
Simplify log2(3) · log3(5) · log_5(16) to a single whole number.
Show answer
The chain rule gives log2(3) · log3(5) · log5(16) = log2(16). Since 2^4 = 16, the value is 4.
Exercise
A student writes log4(x) = ln(x) − ln(4) and then solves log4(x) = 2 to get x = e^(2) · 4. Identify the error and give the correct value of x.
Show answer
The change-of-base formula divides, so log_4(x) = ln(x) / ln(4). Setting this equal to 2 gives ln(x) = 2 ln(4) = ln(16), so x = 16. This also follows directly from the definition: 4^2 = 16.