The Distribution of Primes
Look at the primes up close and they seem to be scattered almost at random: 2, 3, 5, 7, 11, 13, 17,
19, 23, 29 — no formula spits them out, no obvious rhythm tells you where the next one will land.
The primes are infinite,
but up close their appearance looks chaotic.
Now zoom out. Instead of asking "where exactly is the next prime?", ask "roughly
how many primes are there below a million? A billion? A trillion?" Something remarkable happens:
the apparent chaos resolves into a smooth, precise, predictable rate at which primes thin
out. Individual primes are unpredictable; their overall density obeys a law good enough to belong
in a physics textbook. That law is one of the crown jewels of number theory.
Worked example: counting primes below 10 and below 100
Write \pi(x) for the number of primes up to and including
x. Let's count by hand and watch what happens to the density —
the fraction of numbers up to x that are prime.
Below 10: the primes are 2, 3, 5, 7, so
\pi(10) = 4. That's 4 primes out of
10 numbers — a hefty 40% are prime.
Below 100, a careful sieve (or a look-up) gives
\pi(100) = 25 primes. That's only 25% — the density has
nearly halved. Push on to 1000: there are
\pi(1000) = 168 primes, a density of just 16.8%.
| x | \pi(x) | density \pi(x)/x |
| 10 | 4 | 40% |
| 100 | 25 | 25% |
| 1000 | 168 | 16.8% |
| 10\,000 | 1229 | 12.3% |
The trend is unmistakable: as the numbers grow, primes become steadily rarer. The question this
page answers is how fast — and the answer turns out to be exact enough to predict
\pi(x) for numbers you could never hope to sieve by hand.
Counting the primes: \pi(x)
\pi(x) is a staircase: it jumps up by one at every prime and is flat in
between. It looks jagged and irregular close up. Watch how its rising shape is shadowed almost
exactly by a smooth curve as x grows:
The smooth curve: x / \ln x
Gauss, as a teenager poring over tables of primes
for fun, noticed that \pi(x) is tracked closely by
x / \ln x. Equivalently, the density of primes near a large
number x is about 1/\ln x — so a number
picked near x has roughly a 1 / \ln x chance
of being prime. This is the celebrated
Prime Number Theorem,
which we'll state and prove properly later — for now, meet its shape:
\pi(x) \sim \frac{x}{\ln x} \qquad\text{(the ratio} \to 1 \text{ as } x \to \infty).
Proving it took a century after Gauss's guess and required the deep machinery of
complex analysis —
we will return to it in the analytic stage.
Worked example: testing the estimate
Let's put x/\ln x to the test at x = 1000,
where we already counted the true answer by hand.
\frac{1000}{\ln 1000} = \frac{1000}{6.908\ldots} \approx 144.8.
The true count was \pi(1000) = 168. The estimate is in the right
ballpark but noticeably low — off by about 14\%. That's expected: the
theorem only promises the ratio \pi(x) / (x/\ln x) creeps
towards 1 as x \to \infty, and at
x = 1000 we are nowhere near infinity. Try
x = 10^9: there \pi(x) = 50\,847\,534 while
x/\ln x \approx 48\,254\,942 — a much closer 5\%
gap. The bigger the number, the better the smooth law fits.
Gaps: growing on average, but not steadily
If primes near x occur with density about 1/\ln x,
then the typical spacing — the gap between one prime and the next — should be about
\ln x. Near x = 10,
\ln 10 \approx 2.3, and indeed the gaps
3-2, 5-3, 7-5 are 1, 2, 2 — small, matching a
small \ln x. Near x = 100,
\ln 100 \approx 4.6, and the primes
89, 97, 101, 103, 107, 109, 113 have gaps
8, 4, 2, 4, 2, 4 — bigger on average, exactly as predicted.
Gaps can also grow enormously, on purpose. Take n = 5, so
n! = 120. Then 120 + 2 = 122 is divisible by
2, 120 + 3 = 123 is divisible by
3, 120 + 4 = 124 is divisible by
4, and 120 + 5 = 125 is divisible by
5 — four composite numbers in a row, guaranteed, with no primality
testing needed. Crank n up and the same trick — using
n! + 2, n! + 3, \dots, n! + n — manufactures a prime-free run of any
length you like. So gaps really can be made arbitrarily large; it's the typical gap, not
the largest possible one, that grows like \ln x.
But look closely at the list of primes near 100: 101 and 103 are
only 2 apart, and so are 107 and
109. Pairs of primes exactly 2 apart are
called twin primes. Even as the average gap climbs relentlessly with
\ln x, tight little gaps of 2 keep turning up,
seemingly forever. The law governs the average; it says almost nothing about any one gap.
It's tempting to picture the gaps between consecutive primes marching upward in lockstep —
1, 2, 2, 4, 2, 4, 2, 4, 6, 2, \ldots steadily fattening as
x grows. They don't. The Prime Number Theorem is a statement about the
average gap size over a long stretch, not a promise that each individual gap is bigger
than the last.
In fact, twin primes — gap exactly 2, the smallest gap two odd primes
can ever have — keep reappearing among numbers with hundreds of thousands of digits. The current
record pair, found in 2016, is
2\,996\,863\,034\,895 \times 2^{1\,290\,000} \pm 1, each number over
388\,000 digits long — and still a twin pair. The overall trend thins
primes out; it does not forbid two of them from standing shoulder to shoulder, no matter how far
out you look. That coexistence of a strict average law with a wildly irregular local pattern is
the whole point of this page.
Order and chaos, side by side
Here is the honest, slightly unsettling truth: mathematicians understand the overall density
of primes extremely well — the Prime Number Theorem pins it down with total confidence — yet nobody
can predict where the next individual prime will fall, short of testing each candidate one
by one. It's a bit like weather and climate: climate scientists can state with confidence how much
warmer next July will be on average than this January, while no one can tell you whether it will
rain in your town on a specific afternoon eight months from now. Zoomed out, primes obey a precise
law. Zoomed in, they still spring surprises — that tension between order and chaos is exactly why
number theorists find them endlessly fascinating.
The Twin Prime Conjecture guesses that there are infinitely many twin primes —
pairs like (11, 13), (17, 19), and
(1\,000\,000\,000\,061,\ 1\,000\,000\,000\,063). It sounds like it should
be easy — primes clearly keep clustering — but nobody has ever proved it, or disproved it. It has
resisted every attack since it was first written down in the 19th century.
Then, out of nowhere, in 2013 a little-known lecturer named Yitang Zhang proved
something astonishing: there are infinitely many pairs of primes that differ by at most
70\,000\,000 — not 2, but a genuine bounded
number, the first time anyone had pinned down bounded gaps at all. Mathematicians around the world,
working together online in the "Polymath Project," and separately the young mathematician
James Maynard, raced to shrink that bound. Within a couple of years it had fallen
all the way to 246. Getting from 246 down to
the conjectured 2 looks like it needs fundamentally new ideas — so the
Twin Prime Conjecture itself remains open today, a simple question that is still, genuinely,
unknown.