The log10() function computes the common logarithm log10(x)—the logarithm to base 10. It answers “how many times do I multiply 10 to get x?” and appears in decibels, scientific notation, and orders of magnitude.
01
Base 10
Common log.
02
math.h
Link -lm.
03
x > 0
Domain.
04
log10(10)=1
Identity.
05
pow(10,t)
Inverse.
06
vs log
Base e.
Fundamentals
Definition and Usage
The common logarithm answers: “To what power must 10 be raised to get x?” If 10t = x, then log10(x) = t.
In C, log10(x) requires x > 0. log10(1) = 0 because 10&sup0; = 1. log10(10) = 1 because 10¹ = 10. log10(1000) = 3 because 10³ = 1000.
💡
Beginner Tip
On many calculators, the log button means base 10. In C, log() is the natural log (base e) and log10() is base 10. Do not mix them up.
log10(999) is just under 3, so floor gives 2 and +1 yields 3 digits. At exactly 1000, log10 is 3.0—use integer logic or string length for production digit counting.
Example 4 — Decibel Level from Power Ratio
Sound level in decibels uses a base-10 logarithm: dB = 10 × log10(P/Pref).
x = 100
log10(x) = 2.0000 (base 10)
log(x) = 4.6052 (base e)
log(x)/log(10) = 2.0000 (change of base)
How It Works
log10(x) = log(x) / log(10) is the change-of-base formula. Use log10 directly when you want base 10—clearer and often faster than dividing two natural logs.
Applications
🚀 Common Use Cases
Scientific notation — express large/small numbers as mantissa × 10exponent.
Decibels (dB) — compress wide power or amplitude ratios.
Orders of magnitude — compare scales (Richter, stellar brightness).
Digit estimation — floor(log10(n))+1 for positive integers.
Inverse of 10t — solve 10^t = x with t = log10(x).
🧠 How log10() Works
1
Receive positive x
Domain: x > 0 only.
Input
2
Find exponent t
Solve 10t = x for t.
Compute
3
Return log10(x)
The power t as a double.
Output
=
🔢
Common log
Undo powers of ten: pow(10, log10(x)) == x.
Important
📝 Notes
Common log uses base 10, not base e.
Domain: x > 0 only. Zero and negatives are errors.
log10(1) = 0; log10(10) = 1; log10(100) = 2.
Calculator log often means base 10; C log() means natural log.
Change of base: log10(x) = log(x) / log(10.0).
Link with -lm on GCC/Clang Unix-like builds.
Performance
⚡ Optimization
log10() is implemented in the platform math library. Prefer log10(x) over log(x) / log(10.0) when you need base 10—it is clearer and may be faster. In hot loops, profile the overall algorithm first; use log10f when float precision is enough.
Wrap Up
Conclusion
log10() computes the common logarithm log10(x) for positive x. It pairs naturally with powers of ten, appears in decibels and scientific scales, and differs from log() in its base.
Continue with modf() to split fractional parts, or review log() for natural logarithms.
Use log10 for base-10 thinking (digits, dB, powers of 10)
Use log for natural-growth and exp pairs
Include <math.h> and link -lm
Remember log10(10) = 1 and log10(100) = 2
❌ Don’t
Pass zero or negative values to log10
Confuse C log() (base e) with calculator “log” (often base 10)
Assume log(a + b) = log(a) + log(b)—that identity is false
Rely on floor(log10(n))+1 alone at exact powers of 10 without tests
Ignore NaN/INF from bad inputs
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about log10()
Common logarithm in C, explained simply.
5
Core concepts
🔢01
Base 10
Common log.
Basics
📚02
x > 0
Domain.
Rule
📈03
log10(10)=1
Anchor.
Identity
🔊04
dB scales
Real use.
Apply
🔄05
vs log
Base e.
Compare
❓ Frequently Asked Questions
log10(x) returns the common logarithm — the logarithm to base 10. It answers: what power must 10 be raised to, to get x? For example, log10(1000.0) is 3.0 because 10^3 = 1000.
Include <math.h> and link with -lm on many systems: gcc program.c -o program -lm. The function is declared as double log10(double x).
No. The domain is x > 0 only. log10(0) returns negative infinity (-HUGE_VAL) and may set errno to ERANGE. log10(negative) returns NaN and may set errno to EDOM. Always validate input is positive.
log10(x) uses base 10 (common log). log(x) uses base e (natural log). log10(100) is 2.0; log(100) is about 4.605. Use log10 when you think in powers of ten.
They undo each other for base 10. If 10^t = x, then log10(x) = t. For positive x, pow(10.0, log10(x)) equals x. To raise 10 to a power, use pow(10.0, y) or exp(y * log(10.0)).
log10f(x) takes float and returns float. log10l(x) takes long double and returns long double. Use the variant matching your variable type.
Did you know?
The pH scale uses a base-10 logarithm: pH = −log10([H+]). Each step down in pH means ten times more hydrogen ions. That is why small pH changes represent large chemical differences.