Home / Algebra

Logarithms

Logarithms reverse powers and turn products into sums. The visualiser shows how the base and input shape the result.

Controls

base b2.00
evaluate at x8.0

Product → sum demo

y = log_b(x)

the inverse of an exponential

Live Calculation

log₂(x)
0
ln(x)
0
log₁₀(x)
0
log_b(x)
0

Overview

Read a logarithm

A logarithm answers: which exponent turns a positive number into the value I want? It reverses exponentiation, so the output of a logarithm is an exponent.

by = x   ⇔   logb(x) = y

For example, log₂(8) = 3 because 2³ = 8. A real logarithm needs a positive argument x and a positive base b other than 1. The graph and controls below let you change the base and argument and watch that inverse relationship.

Logarithms

Logs invert powers, turn products into sums, and make ratios easier to compare.

Turn a product into a sum

For positive p and q, the product rule is

logb(pq) = logb(p) + logb(q)

With base 2, the demo's starting values p = 8 and q = 4 give log₂(32) = 5 and log₂(8) + log₂(4) = 3 + 2 = 5. Both sides match. The rule does not say that log(p + q) equals log(p) + log(q); it applies to multiplication, with the same base and positive inputs.

Compare bases and scales

Changing the base rescales the output. You can calculate any base using natural logs:

logb(x) = ln(x) / ln(b)

For instance, log₂(8) = ln(8) / ln(2) = 3. Base 2 is common for bits and powers of two; ln means base e; base 10 is useful for decimal orders of magnitude. Follow the curve as you switch among the visualiser's base presets. For the displayed bases, which are all greater than 1, the logarithm increases with x.

The input must stay positive. As x approaches zero from above, logb(x) falls without bound; at zero or below, it is undefined over the real numbers. A logarithmic x-axis changes how horizontal distances are drawn: equal ratios such as 1→10 and 10→100 receive equal spacing. It does not change the function's values.

Why probability calculations use logs

Independent probabilities multiply. Taking a logarithm turns that product into a sum, which avoids trying to store a very small product directly. Here is a short example: multiplying 0.1 by itself 400 times underflows to zero in ordinary floating-point arithmetic, but adding the 400 log-values remains representable.

logarithms.pyPython
Output

For a known outcome with predicted probability p, the negative log-likelihood is −ln(p): assigning a smaller probability gives a larger penalty. At exactly p = 0, this expression is infinite, so practical loss implementations use numerically stable calculations rather than taking the logarithm of a zero probability directly.

Try this above

  1. Choose the 2 base preset and set evaluate at x to 8. The readout should be 3, because 2³ = 8.
  2. Keep base 2 and double evaluate at x from 8 to 16, then 32. Each doubling adds 1 to the logarithm.
  3. Turn on show b^x (the inverse). The exponential and logarithmic curves reflect across the line y = x because the functions undo each other.
  4. Change both inputs in the Product → sum demo. Check that the product's logarithm equals the sum of the two logarithms; keep both inputs positive.
  5. Toggle log-scale the x axis. Compare equal ratios, such as 1 to 10 and 10 to 100, on the horizontal axis.

Sources and next steps

Check yourself

0 of 4

Answer without scrolling back up.

  1. What does log₂(8) = 3 mean?

  2. Which expression equals log_b(pq), for positive p and q?

  3. Which x-values are allowed in a real-valued log_b(x)?

  4. What does changing the logarithm's base do to its value?

Cheat sheet

Logarithms

Turn a product of tiny probabilities into a sum of manageable numbers — the reason loss functions and learning-rate plots use logs.

MATHS · vizlearn.in/maths/logarithms.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.