A Logarithm is Just the Number of Digits
by Malte Skarupke
If you don’t have a good intuition for how logarithms work, (e.g. what does it mean that happiness scales with the log of income? Or why does an algorithm that runs in log(log(x)) steps always run in 5 steps or fewer?) here is how you can explain it to a third grader: It’s the number of digits (roughly). For example it’s the number of zeros in these:
For this to work out we have to transition through zero:
If it bothers you that I’m off by one, because clearly 100 has 3 digits, not 2, you can get the actual number of digits by rounding away from 0 to the next integer.
Where it gets complicated is when you have a number between two round numbers:
We can’t just count the number of digits. It’s got to be somewhere between the other two numbers, coming out to roughly . But lets not worry about those odd cases for now. Where this really helps is when trying to build an intuition for the logarithm rules:
This should now make sense to you. If we replace “log” with “number of digits” in that formula it’s
Here’s an example that makes it obvious that the number of digits after multiplication is the sum of the number of digits before multiplication:
Slightly harder to understand, but also comes out naturally with an example:
Or the other way round:
One way of looking at both of these is that multiplication is shifting digits to the left, division is shifting digits to the right. So if we just want the number of digits, we can count how many digits we’re shifting instead of doing a division/multiplication.
This says that if all we want is the number of digits of a power, we can save ourselves the exponentiation and instead multiply the number of digits of the input.
This one is less intuitive, but it makes sense that taking the power of something multiplies the number of digits. So will have twice as many digits as :
This one is just a notational mess and looks super scary, but it’s the same as the previous example: If we just want the number of digits of a nth-root, we can save ourselves the root-taking and instead divide the number of digits of the input.
Once again not intuitive, but it kinda makes sense that taking the root of something divides the number of digits. So will have half as many digits as . And will have half as many digits as .
Change of Basis
This one is hardest to explain intuitively because it’s about different bases for the logs, so it’s talking about number of digits in different bases. It says that the number of digits can be calculated in any base, and can be changed from one base to another. And to change it you just multiply by a constant. So a number in base 2 will always have C times as many digits as the same number in base 10. The constant C in the formula is which does not depend on the input number , only on the two bases. To go from base 2 to base 10 you multiply by
This means that in a sense all logarithms are the same. Doesn’t matter if you want the number of digits in base 2 or base 10, you can transform from one to the other with a constant.
Lets take the classic example of which is almost the same as :
So we can go from base 2 to base 10 and back just by multiplying or dividing by a constant, 0.301.
Lets try some other numbers, and :
It always works out. I picked numbers here that are close to round numbers in base 10 as well, so we can see that in the last example, 6.0206 is correct because .
This means that the number of digits in base 2 grows just over three times as fast as the number of digits in base 10.
This also means that the original statement is more true: You can always make a logarithm be equal to the number of digits.
- is just the number of digits of multiplied by 3.322.
- is just the number of digits of multiplied by 2.303.
- is just the number of digits.
I hope this is helpful. This has definitely made it easier for me to look at formulas that contain logarithms. I also wish that logarithms were explained to me like this when I first learned about them, but saying that it’s just the number of digits would probably be too simple language for mathematicians. (see e.g. Wikipedia)
I understand that it often doesn’t exactly work, but I think it’s easier to explain the other cases when you start with “it’s just the number of digits.” Then you can explain all the examples at the beginning of this post, , , as being necessary modifications to the simple definition in order to make it work for all positive real numbers.
The benefit is that “number of digits” makes many things obvious, like how fast something grows when it grows with a rate of (if the result goes up by 1, that means a digit was added to the input). I value that intuition and I’m surprised that nobody I know learned logarithms with this intuition.