Logarithms Explained: Rules, Examples & ML Uses

A logarithm answers one simple question: “what power must I raise the base to, to get this number?” It is the inverse of an exponential, and once it clicks, it unlocks everything from sound and earthquake scales to the loss functions that train machine learning models.

logarithm as the inverse of an exponential, shown as a curve
A logarithm undoes exponentiation, growing quickly at first and then flattening.

What is a logarithm?

The logarithm of a number is the exponent that the base must be raised to in order to produce that number. In symbols, the logarithm and the exponential are two ways of writing the same relationship:

$$\log_b x = y \quad\Longleftrightarrow\quad b^{\,y} = x$$

Read it out loud: “the logarithm base $b$ of $x$ equals $y$” means “$b$ raised to the power $y$ gives $x$.” The base $b$ must be positive and not equal to 1, and you can only take the logarithm of a positive number.

The key idea. A logarithm is just an exponent in disguise. Whenever you see $\log_b x$, you are being asked: to what power do I raise $b$ to reach $x$?

Log notation and common bases

Three bases appear so often they get their own shorthand. Knowing which is which removes most beginner confusion about notation:

NameBaseWrittenWhere you meet it
Common log10$\log x$pH, decibels, the Richter scale
Natural log$e \approx 2.718$$\ln x$calculus, growth, machine learning
Binary log2$\log_2 x$computer science, information theory

When a base is not written at all, mathematicians usually mean base 10 and many ML texts mean base $e$ — always check the context.

The logarithm rules

The power of the log is that it turns hard operations into easy ones: multiplication becomes addition, division becomes subtraction, and powers become multiplication. These are the rules worth memorizing:

RuleFormula
Product rule$\log_b(xy) = \log_b x + \log_b y$
Quotient rule$\log_b\!\left(\dfrac{x}{y}\right) = \log_b x – \log_b y$
Power rule$\log_b(x^{\,k}) = k\,\log_b x$
Change of base$\log_b x = \dfrac{\ln x}{\ln b}$
Identities$\log_b 1 = 0$,   $\log_b b = 1$

The change of base formula is especially handy: it lets you compute a log in any base using the natural log button on a calculator.

How to evaluate a log, step by step

  1. Identify the base of the log.
  2. Ask the question “the base to what power gives this number?”
  3. Use the log rules to expand products, quotients and powers into simpler pieces.
  4. Evaluate or simplify each piece.

Worked examples

A few concrete examples make the idea stick:

  • $\log_2 8 = 3$, because $2^3 = 8$.
  • $\log_{10} 1000 = 3$, because $10^3 = 1000$.
  • $\ln e = 1$, because $e^1 = e$.
  • Using the product rule: $\log_2 (4 \cdot 8) = \log_2 4 + \log_2 8 = 2 + 3 = 5$.
  • Using the power rule: $\log_{10}(100^3) = 3\log_{10}100 = 3 \cdot 2 = 6$.
💡 Sanity checkBecause the log grows slowly, big numbers have surprisingly small logs: $\log_{10}$ of a million is just 6. That “compression” is exactly why log scales tame data that spans many orders of magnitude.

Common log vs natural log

The common log (base 10) matches our decimal system, so it is natural for measuring scale — each whole step means “ten times bigger.” The natural log (base $e$) is the one calculus loves, because the slope of $\ln x$ is exactly $1/x$ and the exponential $e^x$ is its own derivative. That clean behavior is why $\ln$ dominates machine learning. You can confirm that derivative with our derivative calculator.

Why the logarithm matters in machine learning

Logs are quietly everywhere in ML, for two reasons. First, they turn fragile products of many small probabilities into stable sums. Second, they stretch out tiny numbers so a computer can work with them without underflowing to zero.

  • Log-likelihood: models maximize the log of the likelihood instead of the likelihood itself, converting a product over thousands of data points into a sum.
  • Log loss / cross-entropy: the standard cost for classification is built from logarithms — see how it drives training in our guide to logistic regression gradient descent.
  • Log scales: features that span many orders of magnitude (income, word counts) are often log-transformed before modeling, the same idea behind logarithmic regression.

🤖 ML insight

When you train a classifier, the optimizer is minimizing a log-based loss. That single mathematical choice — using $\ln$ to turn products into sums — is what makes gradient descent numerically stable. The logarithm is the unsung hero behind supervised learning.

Frequently asked questions

What is a logarithm in simple terms?
It is the exponent you need: the log base b of x is the power that b must be raised to in order to equal x. It is the inverse of exponentiation.
What is the natural log?
A log with base e (about 2.718), written ln. It is common in calculus and machine learning because the slope of ln x is 1/x.
What are the main log rules?
The product rule turns log of a product into a sum, the quotient rule turns a quotient into a difference, the power rule pulls exponents out front, and the change-of-base formula rewrites any base using natural logs.
Why can’t you take the log of zero or a negative number?
Because no power of a positive base ever produces zero or a negative number, so the result is undefined there.
Why does machine learning use logarithms?
Logs turn products of probabilities into sums and keep tiny numbers stable, which is why losses like cross-entropy and log-likelihood are built from logarithms.

Key takeaways

A logarithm is simply an exponent turned inside out — the inverse of an exponential — with a handful of rules that convert multiplication into addition. It powers measurement scales and, above all, the loss functions of machine learning. Keep exploring with the logarithmic regression calculator, the derivative calculator, or the formal logarithm reference on Wikipedia.

Scroll to Top