Number Theory

The Prime Number Theorem and How Primes Thin Out

Learn how fast the primes thin out, what x divided by ln x really predicts, and why a proof took about a century of work.

Key takeaways

  • The counting function π(x) gives the number of primes less than or equal to x.
  • The prime number theorem says the ratio of π(x) to x / ln x approaches 1 as x grows without limit.
  • Near a large number N, the chance that a typical integer is prime behaves like 1 / ln N.
  • The logarithmic integral li(x) is a much closer estimate than x / ln x.
  • The theorem was proved in 1896 by Hadamard and de la Vallée Poussin, working independently.

Primes become rarer as numbers grow, and they do so at a remarkably predictable rate. Near a large number N, roughly one whole number in every ln N is prime, where ln is the natural logarithm. The prime number theorem is the precise form of that statement.

In its usual wording, the number of primes up to x is approximately x divided by ln x, and the approximation gets better in relative terms as x grows. It says nothing about where the next prime will fall. It describes the crowd, not the individual.

Counting the primes

To talk about thinning, you need a way to count. Mathematicians write π(x) for the number of primes that are at most x. This π has nothing to do with the circle constant; it is just a name for a counting function.

There are four primes up to 10 (namely 2, 3, 5 and 7), so π(10) = 4. If the idea of a prime is new to you, start with the ground-up introduction to primes. Longer counts can be made with the sieve of Eratosthenes or a computer.

x                π(x)         share of numbers that are prime
10                  4         40%
100                25         25%
1,000             168         16.8%
10,000          1,229         12.3%
1,000,000      78,498          7.8%
1,000,000,000  50,847,534      5.1%

The share keeps falling, but slowly. Multiplying x by a thousand, from a million to a billion, only lowers it from about 7.8 percent to about 5.1 percent. Euclid showed that the primes never run out, so the count itself keeps rising forever.

What the theorem says

Look at the reciprocal of the share, meaning x divided by π(x). It is 4 at x = 100, about 6 at 1,000, about 12.7 at a million and about 19.7 at a billion. Each time x is multiplied by 1,000, this number climbs by about 7.

That step is a clue. The natural logarithm of 1,000 is about 6.9, and a logarithm is exactly the kind of function that adds a fixed amount each time its input is multiplied by a fixed factor. So the share of primes behaves like 1 / ln x.

The theorem states that π(x) divided by x / ln x tends to 1 as x tends to infinity. In symbols you may see π(x) ~ x / ln x, where ~ means "the ratio approaches 1". The logarithm here uses the number e as its base.

How good is the simple estimate?

You can test the formula against the true counts. The values below are rounded.

x π(x) x / ln x ratio π(x) to estimate
100 25 21.7 1.15
1,000 168 144.8 1.16
1,000,000 78,498 72,382 1.08
1,000,000,000 50,847,534 48,254,942 1.05

The ratio drifts toward 1, but without any hurry. It does not even move in a straight line at the start. The absolute error, the plain difference between the two columns, actually grows. At a billion the estimate is short by more than two and a half million primes.

Both facts fit together. An error can grow in size while shrinking as a fraction of the total, just as a one percent mistake on a large sum is more money than a ten percent mistake on a small one.

Example: share of numbers up to x that are prime (percent)
Up to 10 40% Up to 100 25% Up to 1,000 16.8% Up to 10,000 12.3% Up to 1 million 7.8% Up to 1 billion 5.1% Up to 10 40% Up to 100 25% Up to 1,000 16.8% Up to 10,000 12.3% Up to 1 million 7.8% Up to 1 billion 5.1%

Hypothetical example: the numbers are made up to show the method, not a quote or an average.

A sharper estimate: the logarithmic integral

If the density of primes near t is about 1 / ln t, then the total count should be found by adding up that density all the way to x. Adding up a changing density is what an integral does. The result is called the logarithmic integral, written li(x).

The improvement is dramatic. At x = 1,000, li(x) is about 178, against a true count of 168. At a million it is about 78,628, only about 130 too high. At a billion it is about 50,849,235, high by roughly 1,700 out of fifty million.

For every x in tables like these, li(x) overshoots. It is tempting to conclude that it always does. In 1914 J. E. Littlewood proved otherwise: the difference li(x) − π(x) changes sign infinitely often. The first change happens so far out that no direct count has reached it. This is a famous warning against trusting numerical patterns.

Estimates you can do yourself

Here are three practical uses, each an approximation.

The chance a big number is prime. Near 10¹⁰⁰, the natural logarithm is 100 × ln 10, or about 230. So about one integer in 230 of that size is prime. If you only try odd numbers, your odds double to about one in 115. This is why computers can generate large primes simply by guessing and testing, as described in testing large numbers for primality.

Primes in a short window. Between 1,000,000 and 1,001,000 you would expect about 1,000 / ln 1,000,000 primes.

ln 1,000,000 ≈ 13.8155
1,000 / 13.8155 ≈ 72.4      so expect roughly 70-some primes

The real count will not match exactly, because short windows fluctuate.

The size of the nth prime. The theorem can be turned around: the nth prime is approximately n ln n. For n = 1,000,000 that gives about 13.8 million, while the millionth prime is 15,485,863. A refined version helps a lot.

n (ln n + ln(ln n) − 1)
ln n ≈ 13.816,   ln(ln n) ≈ 2.626
1,000,000 × (13.816 + 2.626 − 1) ≈ 15,442,000

Why one over ln x is a natural guess

There is a loose argument that makes the logarithm plausible, though it is not a proof. A number near x is prime if no prime up to √x divides it. About one number in 2 is a multiple of 2, one in 3 is a multiple of 3, and so on. If these events were independent, the share of survivors would be the product of (1 − 1/p) over all primes p up to √x.

That product does shrink like a constant divided by ln x, a result due to Franz Mertens in the 1870s. So the logarithm appears for a structural reason: every new prime removes a further slice of what remains.

The same argument also shows why such reasoning needs care. The constant it produces is not 1. It overstates the share of primes by about 12 percent in the long run, because divisibility by different primes is not truly independent once the primes become comparable in size to the numbers being tested.

Heuristics of this kind are still valuable. They suggest how often special patterns, such as pairs of primes differing by 2, ought to occur. Number theorists then compare the prediction with computer counts, and finally try to prove it. The prime number theorem is one of the happy cases where the last step has been completed.

What relative accuracy means here

The phrase "approaches 1" is easy to misread. It promises that for any tolerance you name, say one part in a thousand, there is a point beyond which the ratio of π(x) to x / ln x stays within that tolerance forever. It does not promise that the point is small.

For x / ln x, the ratio behaves roughly like 1 + 1 / ln x, so reaching one part in a thousand needs ln x near 1,000. That is a number with more than 400 digits. The logarithmic integral reaches the same accuracy while x is still modest, which is why it is the estimate to prefer whenever you can compute it.

How the theorem was found and proved

Carl Friedrich Gauss studied tables of primes as a young man in the 1790s and guessed that their density near t is about 1 / ln t. He described this much later in a letter. Adrien-Marie Legendre independently proposed a formula of a similar shape and published it.

Around 1850, Pafnuty Chebyshev made the first solid progress. He proved that π(x) stays between two constant multiples of x / ln x for large x, and that if the ratio has a limit at all, that limit must be 1. He could not show that the limit exists.

In 1859 Bernhard Riemann connected the question to a function of a complex variable, the zeta function, building on Euler's product over the primes. Complete proofs followed in 1896 from Jacques Hadamard and Charles de la Vallée Poussin. The key step was showing that the zeta function has no zeros on a particular line in the complex plane.

In the late 1940s Atle Selberg and Paul Erdős found proofs that avoid complex analysis. These are called elementary, which refers to the tools used and not to ease: they are intricate.

The theorem tells you that the error in li(x) is small compared with the count. It does not tell you the smallest possible size of that error.

The Riemann hypothesis, still unproved as of the mid-2020s, would settle this. It is equivalent to saying that the gap between π(x) and li(x) is never much bigger than √x times ln x. In everyday terms, the primes would be spread about as evenly as one could hope, with fluctuations resembling those of random noise. The wider field that studies such questions is analytic number theory.

Common questions

Does the theorem predict which numbers are prime?

No. Primality is completely determined: a number is prime or it is not. The theorem is a statement about averages over long stretches. Thinking of primes as appearing "with probability 1 / ln N" is a helpful model for guessing, but the model ignores obvious facts, such as that even numbers above 2 are never prime.

Why the natural logarithm?

The base is forced by the mathematics. If you used base 10, you would need an extra constant factor of about 2.3 to make the ratio approach 1. With base e no correction is needed.

Do the gaps between primes grow steadily?

The average gap near N is about ln N, so it grows slowly. Individual gaps jump around widely, from 2 to much larger than average. That story is told in prime gaps.

Written for 4Mathematics with AI writing tools and not reviewed line by line by a person. Check anything you rely on against a textbook or primary source. Report an error.

Keep reading

All 59 articles in Number Theory →

Latest news on this topic