Prime Number Theorem Explained: Formula and Examples

Quick answer: The prime number theorem says that the number of primes up to x, written π(x), is approximately x / ln x, in the sense that their ratio tends to 1 as x grows. Equivalently, the proportion of primes among the numbers up to N is about 1 / ln N. Gauss and Legendre conjectured it around 1800, and Jacques Hadamard and Charles de la Vallée Poussin proved it independently in 1896.

Primes thin out as numbers grow: a quarter of the numbers up to 100 are prime, but only about 5% of those up to a billion. Is there a pattern to how fast they thin out? The prime number theorem gives the answer, and it is one of the most beautiful results in mathematics.

The Statement

Let \(\pi(x)\) be the number of primes less than or equal to \(x\). Then

\[ \pi(x) \sim \frac{x}{\ln x}, \quad \text{meaning} \quad \lim_{x \to \infty} \frac{\pi(x)}{x / \ln x} = 1. \]

Here \(\ln x\) is the natural logarithm. An even better approximation is the logarithmic integral \(\operatorname{li}(x) = \int_0^x \frac{dt}{\ln t}\) (taken as a principal value).

Check It With Real Numbers

\(x\)\(\pi(x)\)\(x / \ln x\)\(\operatorname{li}(x)\)
1,000168about 145about 178
1,000,00078,498about 72,382about 78,628
1,000,000,00050,847,534about 48,254,942about 50,849,235

Table values of \(\operatorname{li}(x)\) use the principal-value integral from 0; starting at 2 instead lowers each by about 1.045. The ratio \(\pi(x) / (x/\ln x)\) is 1.16 at a thousand, 1.08 at a million and 1.05 at a billion: slowly approaching 1. The logarithmic integral is far more accurate.

What It Means in Practice

  • Proportion of primes: among the numbers up to \(N\), the fraction that are prime is \(\pi(N)/N \approx 1/\ln N\). Up to a million the true fraction is 7.85%, and \(1/\ln N\) gives 7.24%. As a local heuristic, about 1 in 14 numbers near a million is prime (\(\ln 10^6 \approx 13.8\)), though short stretches vary.
  • Average gap: consecutive primes near \(x\) are about \(\ln x\) apart on average.
  • The \(n\)th prime: \(p_n \approx n \ln n\). For \(n = 1{,}000\) this gives about 6,908; the true 1,000th prime is 7,919.

Cryptography relies on this: it tells you how many random tries it takes to find a large prime for an RSA key.

A Short History

YearStep
1792 to 1793Carl Friedrich Gauss, about 15 or 16 by his later recollection, notices primes near \(x\) have density about \(1/\ln x\)
1798; 1808Adrien-Marie Legendre publishes an approximation, in 1808 \(x / (\ln x – 1.08366)\)
1850sPafnuty Chebyshev proves \(\pi(x)\) is within constant factors of \(x/\ln x\)
1859Bernhard Riemann links primes to the zeros of the zeta function
1896Jacques Hadamard and Charles de la Vallée Poussin prove the theorem independently, using complex analysis
1948 to 1949Paul Erdős and Atle Selberg find “elementary” proofs without complex analysis

The key step in 1896 was showing that the Riemann zeta function has no zeros on the line where the real part equals 1.

The Error Term and the Riemann Hypothesis

How far can \(\pi(x)\) stray from \(\operatorname{li}(x)\)? The Riemann Hypothesis is equivalent to

\[ \pi(x) = \operatorname{li}(x) + O(\sqrt{x} \ln x), \]

an upper bound on the error up to a constant. The prime number theorem itself was proved in 1896 without RH. On November 21, 2026, the Lean and Mathlib communities certified a formal proof of RH released by Levent Alpöge; the Clay Institute still lists RH as unsolved pending its own process.

Computer-Checked Proofs

The prime number theorem was first checked by computer in 2004 (Jeremy Avigad and colleagues, in Isabelle; paper 2005). In January 2024, Terence Tao and Alex Kontorovich launched a Lean project to formalize the stronger version with an error term. In September 2025, Math, Inc. reported that its AI agent Gauss completed that strong PNT formalization in about three weeks, roughly 25,000 lines of Lean, with human scaffolding and review and building on the existing PrimeNumberTheoremAnd project. See our Lean explainer.

Common Misconceptions

“x/ln x gives the exact count.” No. It is an approximation whose relative error shrinks; the absolute difference actually grows.

“Primes eventually run out.” No. Euclid proved there are infinitely many; the theorem says how sparse they become.

Watch: The Prime Number Theorem in Video

If you learn better by watching, these videos are worth your time.

The Prime Number Theorem, an introduction (Socratica). A clear, short introduction to π(x) and x/ln x.
The prime number theorem (Khan Academy Labs). A visual explanation of prime density, from a cryptography series.
Why do prime numbers make these spirals? | Dirichlet’s theorem and pi approximations (3Blue1Brown). A beautiful look at prime patterns, including prime density.

Check Your Understanding

Five quick questions to see how much of this has stuck. Pick an answer and press Submit; you will see a short explanation either way.

Answer each question and press Submit to see your result right away.

1. What does π(x) count?
Found a bug? Let us know!
2. According to the prime number theorem, π(x) is approximately:
Found a bug? Let us know!
3. Near one million, roughly what fraction of numbers are prime (local estimate)?
Found a bug? Let us know!
4. Who proved the prime number theorem in 1896?
Found a bug? Let us know!
5. Which famous conjecture controls the error in the prime number theorem?
Found a bug? Let us know!

Frequently Asked Questions

What is the prime number theorem in simple terms?

It says the number of primes up to x is roughly x divided by the natural logarithm of x, and the approximation gets better in relative terms as x grows.

Who proved the prime number theorem?

Jacques Hadamard and Charles de la Vallée Poussin proved it independently in 1896. Erdős and Selberg found elementary proofs in 1948 to 1949.

How is the prime number theorem related to the Riemann Hypothesis?

The prime number theorem follows from knowing zeta has no zeros with real part 1. The Riemann Hypothesis, about all nontrivial zeros, would give the best possible error term, about √x ln x.

How many primes are there below one billion?

There are 50,847,534 primes below one billion. The estimate x / ln x gives about 48.25 million, and li(x) gives about 50.85 million.

Keep Exploring

Sources and Further Reading

Related to This Article

What people say about "Prime Number Theorem Explained: Formula and Examples - Effortless Math"?

No one replied yet.

Leave a Reply