{"course":{"slug":"maths-you-need","title":"The Maths You Actually Need","url":"https://addaly.com/learn/maths-you-need","level":"intermediate","track":"deep"},"lesson":{"slug":"logarithms-from-scratch","title":"What a log is, and why the axis got logged","url":"https://addaly.com/learn/maths-you-need/logarithms-from-scratch","position":39,"of":76,"minutes":8,"answer":"A logarithm counts how many multiplications reach a number, which turns products into sums and equal ratios into equal spacings.","keyIdea":"A logarithm counts how many multiplications reach a number, which turns products into sums and equal ratios into equal spacings, and that is why probabilities are added in log space and why any axis spanning several orders of magnitude should be logged."},"body":{"format":"markdown","text":"## A log counts multiplications\n\nA logarithm answers one question: how many times must I multiply the base by itself to reach this number? `log2(1024) = 10` because ten doublings reach 1,024. `log10(1,000,000) = 6` because six tens do. That is the whole definition. Everything else is consequence.\n\nThree bases matter in this field.\n\n- **Base 2** counts doublings and gives answers in bits. `log2(32000) = 14.97`, so choosing one token from a 32,000-word vocabulary is about fifteen yes-or-no questions.\n- **Base 10** counts orders of magnitude. A learning rate of 0.001 sits at `log10 = -3`.\n- **Base e**, written `ln`, where `e = 2.71828`. It is the one calculus prefers, because the slope of `e^x` is `e^x`. Every loss you will see from PyTorch is in this base, in units called nats.\n\nYou convert between them by one multiplication: `ln x = 2.303 × log10 x` and `log2 x = 1.443 × ln x`. Remember `ln 2 = 0.693` and `ln 10 = 2.303`; they come up constantly.\n\n## The four rules, and the one that matters\n\n```\nlog(a × b) = log a + log b\nlog(a / b) = log a − log b\nlog(a^k)   = k × log a\nlog_b(x)   = ln x / ln b\n```\n\nThe first rule is the reason logs exist in machine learning. A model that assigns probability 0.9 to each of 200 tokens in a sentence assigns the sentence `0.9^200 = 7 × 10^-10`. Multiply another hundred such sentences together and the product is below anything a computer can store. Take logs first and the product becomes a sum: `200 × ln 0.9 = −21.07`. Sums of moderate numbers stay moderate. Module 8 returns to exactly how small a number can get before it becomes zero.\n\n## Why the axis got logged\n\nTake a learning-rate sweep over 0.00001, 0.0001, 0.001, 0.01 and 0.1. On a linear axis the first four values share the leftmost pixel and the fifth sits alone at the right. On a log axis they are evenly spaced, because equal spacing on a log axis means equal *ratio*, not equal difference. Each grid line is ten times the last.\n\nThe same applies to loss curves. A loss that falls from 8 to 4 in the first hundred steps and from 2.1 to 2.0 in the last ten thousand is invisible in its late phase on a linear plot. On a log y-axis the late phase is still readable, and something else appears: a curve that is a straight line on log-log axes is a power law, and one that is straight on a log-linear axis is an exponential. The last lesson of this module teaches you to read the slope. For now, the habit: if the quantity spans more than two orders of magnitude, log the axis.\n\n```python\nimport matplotlib.pyplot as plt\nplt.plot(steps, loss)\nplt.yscale(\"log\")   # one line; nothing else changes\n```\n\n## Two things a log axis cannot show\n\n**Zero.** `log(0)` is minus infinity. A curve that reaches zero loss leaves the bottom of a log plot rather than touching an axis, and a bar chart with a zero bar has no bar. If your data contain zeros, plotting `log(x + 1)` is the usual compromise; say so on the axis label, because it distorts the small values.\n\n**Negatives.** The log of a negative number is not a real number. Losses are non-negative, so this rarely bites there, but a log axis on a plot of gradients or weight changes silently drops every negative point.\n\nA related trap is the `epsilon` people add to avoid the zero: `log(p + 1e-9)`. It works, but `log(1e-9) = −20.7`, so a probability the model put at exactly zero is scored as a surprise of 20.7 nats rather than infinity. That is a choice, and it changes the average. Pick the epsilon consciously and keep it the same across every run you intend to compare.\n\n## Everyday logs you already read\n\nDecibels are `10 × log10` of a power ratio, so 30 dB is a thousandfold. Earthquake magnitude is base 10, so a magnitude 7 releases about 32 times the energy of a 6. pH is a negative log. The screen brightness slider on most phones is logarithmic because perception is. You have been reading log scales for years; the only new thing is doing so on purpose.\n\n## Tools\n\nPython gives you `math.log` (base e), `math.log2`, `math.log10` and `math.log(x, base)`. NumPy applies them to whole arrays. A phone calculator has `log` and `ln`. Nothing here needs a GPU or a paid licence.\n\nOne exercise, done once, fixes the idea: compute `ln(32000)` on a calculator, divide by `ln 2`, and confirm you get 14.97. Then compute a model's reported loss of 2.0 nats in bits: `2.0 × 1.443 = 2.89`. That model needs just under three bits per token, against fifteen for a uniform guess. The next lessons say what those bits mean."},"check":{"question":"A training loss is plotted with a logarithmic y-axis and the curve is a straight line sloping downward. What does that shape tell you?","options":[{"text":"The loss is falling by the same amount every step, so it will reach zero where the line meets the axis.","correct":false,"tempting":"Reads a log axis as if it were linear; equal spacing on a log axis is equal ratio, and zero is not on the axis at all."},{"text":"The loss shrinks by the same factor every fixed number of steps.","correct":true},{"text":"The loss follows a power law in the step count.","correct":false,"tempting":"A power law is straight on log-log axes; with only the y-axis logged, a straight line is an exponential."},{"text":"The plot is broken, because a log axis compresses everything into a curve.","correct":false,"tempting":"A log axis expands the small values rather than compressing them; a straight line on it is a real and informative shape."}]},"prev":{"slug":"heavy-tails-and-why-averages-lie","title":"Heavy tails, and the average that describes nobody","url":"https://addaly.com/learn/maths-you-need/heavy-tails-and-why-averages-lie"},"next":{"slug":"exponentials-decay-and-moving-averages","title":"Exponentials, decay, and the memory of a moving average","url":"https://addaly.com/learn/maths-you-need/exponentials-decay-and-moving-averages"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'What a log is, and why the axis got logged', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/logarithms-from-scratch (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"What a log is, and why the axis got logged","courseTitle":"The Maths You Actually Need","module":{"index":5,"slug":"logs-information-and-loss","title":"Logarithms, information and the shape of a loss"},"answer":null,"keyIdea":"A logarithm counts how many multiplications reach a number, which turns products into sums and equal ratios into equal spacings, and that is why probabilities are added in log space and why any axis spanning several orders of magnitude should be logged.","hero":{"kind":"plate","image":null,"alt":null,"caption":null},"blocks":[{"t":"h2","id":"a-log-counts-multiplications","runs":[{"text":"A log counts multiplications"}]},{"t":"p","runs":[{"text":"A logarithm answers one question: how many times must I multiply the base by itself to reach this number? "},{"text":"log2(1024) = 10","code":true},{"text":" because ten doublings reach 1,024. "},{"text":"log10(1,000,000) = 6","code":true},{"text":" because six tens do. That is the whole definition. Everything else is consequence."}]},{"t":"p","runs":[{"text":"Three bases matter in this field."}]},{"t":"ul","items":[[{"text":"Base 2","b":true},{"text":" counts doublings and gives answers in bits. "},{"text":"log2(32000) = 14.97","code":true},{"text":", so choosing one token from a 32,000-word vocabulary is about fifteen yes-or-no questions."}],[{"text":"Base 10","b":true},{"text":" counts orders of magnitude. A learning rate of 0.001 sits at "},{"text":"log10 = -3","code":true},{"text":"."}],[{"text":"Base e","b":true},{"text":", written "},{"text":"ln","code":true},{"text":", where "},{"text":"e = 2.71828","code":true},{"text":". It is the one calculus prefers, because the slope of "},{"text":"e^x","code":true},{"text":" is "},{"text":"e^x","code":true},{"text":". Every loss you will see from PyTorch is in this base, in units called nats."}]]},{"t":"p","runs":[{"text":"You convert between them by one multiplication: "},{"text":"ln x = 2.303 × log10 x","code":true},{"text":" and "},{"text":"log2 x = 1.443 × ln x","code":true},{"text":". Remember "},{"text":"ln 2 = 0.693","code":true},{"text":" and "},{"text":"ln 10 = 2.303","code":true},{"text":"; they come up constantly."}]},{"t":"h2","id":"the-four-rules-and-the-one-that-matters","runs":[{"text":"The four rules, and the one that matters"}]},{"t":"code","lang":"","label":"Text","text":"log(a × b) = log a + log b\nlog(a / b) = log a − log b\nlog(a^k)   = k × log a\nlog_b(x)   = ln x / ln b"},{"t":"p","runs":[{"text":"The first rule is the reason logs exist in machine learning. A model that assigns probability 0.9 to each of 200 tokens in a sentence assigns the sentence "},{"text":"0.9^200 = 7 × 10^-10","code":true},{"text":". Multiply another hundred such sentences together and the product is below anything a computer can store. Take logs first and the product becomes a sum: "},{"text":"200 × ln 0.9 = −21.07","code":true},{"text":". Sums of moderate numbers stay moderate. Module 8 returns to exactly how small a number can get before it becomes zero."}]},{"t":"h2","id":"why-the-axis-got-logged","runs":[{"text":"Why the axis got logged"}]},{"t":"p","runs":[{"text":"Take a learning-rate sweep over 0.00001, 0.0001, 0.001, 0.01 and 0.1. On a linear axis the first four values share the leftmost pixel and the fifth sits alone at the right. On a log axis they are evenly spaced, because equal spacing on a log axis means equal "},{"text":"ratio","i":true},{"text":", not equal difference. Each grid line is ten times the last."}]},{"t":"p","runs":[{"text":"The same applies to loss curves. A loss that falls from 8 to 4 in the first hundred steps and from 2.1 to 2.0 in the last ten thousand is invisible in its late phase on a linear plot. On a log y-axis the late phase is still readable, and something else appears: a curve that is a straight line on log-log axes is a power law, and one that is straight on a log-linear axis is an exponential. The last lesson of this module teaches you to read the slope. For now, the habit: if the quantity spans more than two orders of magnitude, log the axis."}]},{"t":"code","lang":"python","label":"Python","text":"import matplotlib.pyplot as plt\nplt.plot(steps, loss)\nplt.yscale(\"log\")   # one line; nothing else changes"},{"t":"h2","id":"two-things-a-log-axis-cannot-show","runs":[{"text":"Two things a log axis cannot show"}]},{"t":"p","runs":[{"text":"Zero.","b":true},{"text":" "},{"text":"log(0)","code":true},{"text":" is minus infinity. A curve that reaches zero loss leaves the bottom of a log plot rather than touching an axis, and a bar chart with a zero bar has no bar. If your data contain zeros, plotting "},{"text":"log(x + 1)","code":true},{"text":" is the usual compromise; say so on the axis label, because it distorts the small values."}]},{"t":"p","runs":[{"text":"Negatives.","b":true},{"text":" The log of a negative number is not a real number. Losses are non-negative, so this rarely bites there, but a log axis on a plot of gradients or weight changes silently drops every negative point."}]},{"t":"p","runs":[{"text":"A related trap is the "},{"text":"epsilon","code":true},{"text":" people add to avoid the zero: "},{"text":"log(p + 1e-9)","code":true},{"text":". It works, but "},{"text":"log(1e-9) = −20.7","code":true},{"text":", so a probability the model put at exactly zero is scored as a surprise of 20.7 nats rather than infinity. That is a choice, and it changes the average. Pick the epsilon consciously and keep it the same across every run you intend to compare."}]},{"t":"h2","id":"everyday-logs-you-already-read","runs":[{"text":"Everyday logs you already read"}]},{"t":"p","runs":[{"text":"Decibels are "},{"text":"10 × log10","code":true},{"text":" of a power ratio, so 30 dB is a thousandfold. Earthquake magnitude is base 10, so a magnitude 7 releases about 32 times the energy of a 6. pH is a negative log. The screen brightness slider on most phones is logarithmic because perception is. You have been reading log scales for years; the only new thing is doing so on purpose."}]},{"t":"h2","id":"tools","runs":[{"text":"Tools"}]},{"t":"p","runs":[{"text":"Python gives you "},{"text":"math.log","code":true},{"text":" (base e), "},{"text":"math.log2","code":true},{"text":", "},{"text":"math.log10","code":true},{"text":" and "},{"text":"math.log(x, base)","code":true},{"text":". NumPy applies them to whole arrays. A phone calculator has "},{"text":"log","code":true},{"text":" and "},{"text":"ln","code":true},{"text":". Nothing here needs a GPU or a paid licence."}]},{"t":"p","runs":[{"text":"One exercise, done once, fixes the idea: compute "},{"text":"ln(32000)","code":true},{"text":" on a calculator, divide by "},{"text":"ln 2","code":true},{"text":", and confirm you get 14.97. Then compute a model’s reported loss of 2.0 nats in bits: "},{"text":"2.0 × 1.443 = 2.89","code":true},{"text":". That model needs just under three bits per token, against fifteen for a uniform guess. The next lessons say what those bits mean."}]}],"check":{"question":[{"text":"A training loss is plotted with a logarithmic y-axis and the curve is a straight line sloping downward. What does that shape tell you?"}],"options":[{"text":[{"text":"The loss is falling by the same amount every step, so it will reach zero where the line meets the axis."}],"correct":false,"tempting":[{"text":"Reads a log axis as if it were linear; equal spacing on a log axis is equal ratio, and zero is not on the axis at all."}]},{"text":[{"text":"The loss shrinks by the same factor every fixed number of steps."}],"correct":true,"tempting":null},{"text":[{"text":"The loss follows a power law in the step count."}],"correct":false,"tempting":[{"text":"A power law is straight on log-log axes; with only the y-axis logged, a straight line is an exponential."}]},{"text":[{"text":"The plot is broken, because a log axis compresses everything into a curve."}],"correct":false,"tempting":[{"text":"A log axis expands the small values rather than compressing them; a straight line on it is a real and informative shape."}]}],"order":[2,3,0,1],"why":null},"prev":{"slug":"heavy-tails-and-why-averages-lie","title":"Heavy tails, and the average that describes nobody","minutes":9},"next":{"slug":"exponentials-decay-and-moving-averages","title":"Exponentials, decay, and the memory of a moving average","minutes":9}}}