Crash Course on Logarithms

Crash Course on Logarithms

Logarithms are one of the most useful mathematical tools — from calculating algorithmic complexity to dealing with exponential growth in real life.
In this quick crash course, you’ll understand what logarithms are, how they work, and how to apply them.


What is a Logarithm?

A logarithm answers the question:

“To what power must I raise this base to get that number?”

Formally:

\[ \log_b(a) = c \iff b^c = a \]

Example

\[ \log_2(8) = 3 \text{ because } 2^3 = 8 \]

Common Logarithm Bases

BaseNameExample
10Common Logarithmlog₁₀(1000) = 3
2Binary Logarithmlog₂(32) = 5
e (≈2.718)Natural Logarithm (ln)ln(e²) = 2

Tip: In programming and algorithms, log often means log₂.


Why Do We Use Logarithms?

  1. Simplify exponential growth: Convert multiplication into addition.
    e.g., \(\log(ab) = \log(a) + \log(b)\)
  2. Measure complexity: Big-O like O(log n) appears in binary search, tree height, etc.
  3. Handle large numbers: Makes huge values manageable (e.g., sound intensity, earthquakes).
  4. Undo exponentials: Solve for unknown exponents easily.

Logarithm Properties (Must-Know)

PropertyFormulaExample
Productlogₐ(xy) = logₐ(x) + logₐ(y)log₂(8×4) = log₂(8) + log₂(4) = 3 + 2 = 5
Quotientlogₐ(x/y) = logₐ(x) − logₐ(y)log₁₀(100/10) = 2 − 1 = 1
Powerlogₐ(xᵖ) = p × logₐ(x)log₂(8²) = 2 × 3 = 6
Change of Baselogₐ(b) = log_c(b) / log_c(a)log₂(8) = log₁₀(8) / log₁₀(2) = 0.903 / 0.301 = 3

Quick Practice

Try these:

  1. \(\log_3(81) = ?\)
    → 81 = 3⁴ → Answer = 4

  2. \(\log_5(1/25) = ?\)
    → 1/25 = 5⁻² → Answer = -2

  3. \(\log_{10}(0.01) = ?\)
    → 0.01 = 10⁻² → Answer = -2


Logarithms in Programming

LanguageFunctionExample
Pythonmath.log(x, base)math.log(8, 2) → 3.0
JavaScriptMath.log(x)/Math.log(base)Math.log(8)/Math.log(2) → 3
Gomath.Log(x)/math.Log(base)math.Log(8)/math.Log(2) → 3
C++log(x)/log(base)log(8)/log(2) → 3

Real-World Applications

  • Algorithms: Binary search, tree depth, sorting complexities.
  • Finance: Compound interest & time to double money.
  • Science: pH scale (logarithmic measure of acidity).
  • Technology: Decibel scale for sound, Richter scale for earthquakes.
  • AI & Data Science: Cross-entropy, log-likelihood in model evaluation.

Intuitive Analogy

Think of logarithms like counting how many times you multiply the base to reach a number.

Example:

StepPower of 2Value
12¹2
22²4
32³8
42⁴16

So, log₂(16) = 4, because you multiply 2 four times to reach 16.


Logarithmic Scales Simplify the Universe

PhenomenonScaleExample
SoundDecibel (dB)Every +10 dB = 10× intensity
EarthquakeRichter+1 magnitude = 10× stronger
LightLuminosity scaleLogarithmic response of eyes
InformationBitslog₂(n) represents choices among n outcomes

Conclusion

Logarithms turn multiplication into addition, division into subtraction, and powers into multipliers.
They are everywhere — from coding algorithms to understanding the world’s natural scales.

So next time you see O(log n), just smile — you now know what that really means.


Takeaway

A logarithm tells you how many times you multiply the base to get a number.


Written by Naman Attri
Built with love and curiosity for lifelong learners.