Prime Distribution & the Prime Counting Function

Explore how primes thin out among integers, the Prime Number Theorem, and the race to count primes

How Are Primes Distributed?

Primes become rarer as numbers grow, but how much rarer? The Prime Number Theorem (proved independently by Hadamard and de la Vallée-Poussin in 1896) gives the answer: the number of primes up to x is approximately x/ln(x).

But while the global trend is smooth, the local behavior of primes is wildly irregular. Prime gaps fluctuate unpredictably, and geometric arrangements of primes reveal mysterious patterns that remain unexplained to this day.

Demo 1: The Prime Counting Function

The function π(x) counts primes up to x. Compare it with two approximations: x/ln(x) (crude but famous) and Li(x), the logarithmic integral (far more accurate). Watch them converge as x grows — this is the Prime Number Theorem in action.

01837552001π(x)x/ln(x)Li(x)

Prime Number Theorem: π(x) ~ x/ln(x) as x → ∞. The logarithmic integral Li(x) is a better approximation.

Demo 2: Prime Gaps

The gaps between consecutive primes reveal the local irregularity beneath the smooth global trend. Twin primes (gap 2) are the closest pairs, while large gaps also appear. The twin prime conjecture — that there are infinitely many twin primes — remains one of the great open problems.

022prime value
Twin (2)Cousin (4)Sexy (6)Found 199 pairs

Demo 3: Prime Spirals

Beyond the Ulam spiral, other geometric arrangements reveal different prime patterns. The Sacks spiral places n at angle 2π√n and radius √n, producing striking radial lines of primes that correspond to quadratic polynomials.

Sacks spiral: integer n placed at angle 2π√n, radius √n. Primes form striking radial lines.

Demo 4: Bertrand's Postulate

Despite their irregularity, primes are never too sparse: for every n ≥ 1, there is always a prime between n and 2n. This was conjectured by Bertrand (1845) and proved by Chebyshev (1850), with a famously elegant proof later given by Erdős at age 19.

5
6
7
8
9
10
n
11
12
13
14
15
16
17
18
19
20
2n
21
22
23
24
25
4 primes in (10, 20)
11, 13, 17, 19
Bertrand's Postulate: For every n ≥ 1, there exists a prime p with n < p < 2n. Proved by Chebyshev (1850) and later by Erdős (1932) with an elementary proof.

Distribution Explored!

You now understand both the global order and local chaos of prime distribution:

  • The Prime Number Theorem: π(x) ~ x/ln(x)
  • Prime gaps and the twin prime conjecture
  • Geometric patterns in spiral arrangements
  • Bertrand's Postulate: primes are always nearby

Next: We reach the summit — the Riemann Zeta Function, the most important function in all of number theory, which encodes the distribution of primes in its zeros.