The Prime Staircase

Primes look random one at a time and lawful in bulk. Count them, weigh them the way Chebyshev did, and measure how far the best smooth guess is from the truth: the gap the Riemann hypothesis, proved in 2026, is about

The Prime Staircase

One at a time, the primes look scattered at random. Counted in bulk, they follow a law so smooth that Gauss guessed it as a teenager. This whole module is about the gap between that smooth law and the true count: how big it is, and what controls it. The answer is the Riemann hypothesis, which was proved in November 2026.

The Staircase at Every Scale

Press Play to zoom out from a few hundred numbers to ten million and watch the steps melt into a curve. Then drag the picture or move the sliders, and compare how many primes the window holds with Gauss’s rule of one in ln x.

—
π(b): primes up to the right edge b = 1,120
—
error of x/ln x at b (it says —)
—
error of li(x) at b (it says —)
—
error of R(x) at b (it says —)
—
of this window is prime: — of 241 numbers, counted
—
Gauss’s density 1/ln x, averaged over the window
The sieve is still running.

TableThe guesses at each power of ten

Every π(x) here was counted by the sieve running in this page. “Digits right” is how many leading digits of the rounded guess agree with the true count.

xπ(x)x/ln x − π(x)li(x) − π(x)R(x) − π(x)digits right: liR
10¹………………
10²………………
10³………………
10⁴………………
10⁵………………
10⁶………………
10⁷………………
π(x), counted exactlyx/ln xli(x), GaussR(x), Riemann

The amber staircase is π(x), the number of primes up to x, from a sieve of every number up to ten million run in this page (the cap for this demo). It rises by one at each prime; amber ticks on the axis mark the primes when there is room. The smooth curves are guesses: x/ln x; li(x), the integral of 1/ln t from 0 to x; and Riemann’s R(x), which corrects li(x) for the squares, cubes and higher powers of primes. When a guess is too far from the staircase to fit in a narrow window, the picture says how far instead of squashing the steps. The readouts are taken at the right edge b of the window.

Go deeper:Gauss’s Guess and the Prime Number Theorem

Write π(x) for the number of primes up to x. In a letter to the astronomer Encke in 1849, Gauss recalled that as a boy, in 1792 or 1793, he had studied tables of primes and noticed that near x about one number in ln x is prime. Adding up that density gives the logarithmic integral, li(x) = ∫0x dt/ln t (taken as a principal value across t = 1). Legendre published a different guess in 1808, x/(ln x − 1.08366), with the constant fitted to the tables he had. For large x both are close to x/ln x, but li(x) is far the better of the two, because it adds up the density at every t instead of using the density at x for the whole range. The demo’s table shows the difference: at ten million, x/ln x has one digit right and li(x) has three.

The first proofs came from Chebyshev, around 1850. He showed that for all sufficiently large x the ratio of π(x) to x/ln x lies between 0.92129 and 1.10555, and that if the ratio tends to a limit, the limit is 1. “Sufficiently large” matters: at x = 10,000 the ratio is still 1.13, and the sieve on this page finds it inside Chebyshev’s two constants only from x = 96,098 onwards.

That the ratio does tend to 1 is the prime number theorem, π(x) ~ li(x), proved independently by Jacques Hadamard and Charles-Jean de la Vallée Poussin in 1896. Both proofs go through the zeta function of a complex variable, following the plan Riemann had laid out in 1859: the theorem is equivalent to the statement that zeta has no zeros on the line Re s = 1. A proof that avoids complex analysis was found by Atle Selberg and Paul Erdős in 1948–49. It is called elementary, which does not mean easy.

Riemann’s own approximation, R(x) = li(x) − ½ li(x1/2) − ⅓ li(x1/3) − ⅕ li(x1/5) + ⅙ li(x1/6) − …, is usually closer still, as the table shows. Why those corrections belong there is the subject of the next demo, and what R(x) still leaves out is the subject of Primes from Zeros. See also the Number Theory module’s Prime Distribution lesson for prime gaps and the Ulam spiral.

Counting Without Listing

Move over the first chart to see Chebyshev’s weighted count hug the line y = x. Switch the sieving primes off and on in the grid, then choose a power of ten up to 1013 and press Run to count its primes without ever listing them.

1Chebyshev’s weighing: count each prime power as ln p

Move over the chart to read ψ(x) against x. The staircase now climbs a straight line instead of a curve.

996.68
ψ(1,000), summed here
0.99668
ψ(x)/x at the right edge: the prime number theorem says this tends to 1
−3.32
ψ(x) − x at the right edge
−0.105
the same, divided by √x
2 ×23 ×34 ×25 ×567 ×78 ×29 ×31011 ×111213 ×13141516 ×217 ×171819 ×1920212223 ×232425 ×52627 ×32829 ×2930

lcm(1, …, 30) = 2,329,089,562,800

28.476499
ln lcm(1, …, 30), from the exact integer
28.476499
ψ(30), from adding the weights
0.949
ψ(n)/n

Amber is ψ(x), which adds ln p whenever x passes a prime p or one of its powers; sky is the line y = x. The least common multiple of 1, …, n is multiplied by p exactly when n reaches a power of p (the amber chips), so its logarithm is ψ(n): the prime number theorem says that lcm(1, …, n) grows like en. The lcm is computed exactly with big integers; the range of the chart is capped at a million.

2Legendre’s idea: count what is left without looking at it

Switch the sieving primes on and off. The count of survivors on the right never looks at the grid: it only divides 100 by products of the chosen primes.

Strike out multiples of
+100100
−117⌊100/2⌋ = 50, ⌊100/3⌋ = 33, ⌊100/5⌋ = 20, ⌊100/7⌋ = 14
+45⌊100/6⌋ = 16, ⌊100/10⌋ = 10, ⌊100/14⌋ = 7, ⌊100/15⌋ = 6, ⌊100/21⌋ = 4, ⌊100/35⌋ = 2
−6⌊100/30⌋ = 3, ⌊100/42⌋ = 2, ⌊100/70⌋ = 1, ⌊100/105⌋ = 0
+0⌊100/210⌋ = 0
= 22by the formula; the grid has 22 survivors
Every composite number up to 100 has a prime factor of at most 10, so the survivors are the number 1 and the primes above 7. Put back the four sieving primes and take away the 1: π(100) = 22 + 4 − 1 = 25. Nobody listed the primes between 10 and 100.

3The same idea, organised: π(x) far beyond any list

Choose x and press Run. Sieving by p removes the multiples p·m whose m has no smaller prime factor, and how many of those there are is itself a count of the same kind, for x/p in place of x. So only the counts at x, x/2, x/3, … are ever needed.

x =
not run yet
xπ(x), computed herepublished valueli(x)R(x)π(x) − li(x)÷ (√x/ln x)numbers storedtime
The first runs are starting.
computed in this page, just nowli(x)the error

Lime is what this page computed. The method keeps, for each v of the form ⌊x/k⌋, the count of numbers up to v that are prime or have no prime factor up to p, and updates the counts as p rises to √x; what is left at x is π(x). It stores about 2√x numbers and takes roughly x3/4 steps, so it never holds a list of the primes up to x: for x = 1013 that list would have 346 billion entries. The cap here is 1013, where the two tables take about 50 MB. On the laptop this was written on, 1011 took about a tenth of a second and 1013 about two seconds; a phone may need several times longer. The published values are from the literature and are only compared with, never used. All arithmetic is exact: every count is a whole number below 253.

Go deeper:Chebyshev’s ψ, Legendre’s Formula and Its Descendants

Chebyshev’s two functions weigh the primes instead of counting them. θ(x) adds ln p for each prime p ≤ x, and ψ(x) adds ln p for each power pk ≤ x as well, so that ψ(x) = θ(x) + θ(x1/2) + θ(x1/3) + …. The weight ln p exactly cancels the thinning of the primes, and the prime number theorem becomes the plain statement ψ(x) ~ x. That is the form in which it is proved, and the form in which the zeros of zeta enter. Because ψ(n) is the logarithm of the least common multiple of 1, …, n, the same theorem says that this lcm grows like en.

Legendre’s formula of 1808 counts the numbers up to x that survive sieving by the primes up to √x, using inclusion and exclusion: subtract the multiples of each prime, add back the multiples of each product of two, and so on. What survives is 1 and the primes between √x and x, so π(x) = φ(x, a) + a − 1, where a = π(√x) and φ(x, a) counts the survivors. Only the primes up to √x are needed, but the number of terms is 2a. The astronomer Ernst Meissel reorganised the sum so that most terms never have to be written down, and in the 1870s and 1880s computed π(x) by hand as far as x = 109. His last value was slightly wrong. D. H. Lehmer simplified the method for a computer in 1959 and corrected it.

The demo uses the recursion at the heart of all these methods, φ(v, p) = φ(v, p − 1) − φ(v/p, p − 1), arranged as a table over the values ⌊x/k⌋, of which there are only about 2√x. It takes roughly x3/4 steps. Programmers know this arrangement as the Lucy_Hedgehog algorithm, after the pseudonym of the person who popularised it. In 1985 Jeffrey Lagarias, Victor Miller and Andrew Odlyzko brought the cost of the combinatorial method down to about x2/3, and in 1987 Lagarias and Odlyzko described an analytic method that computes π(x) from the zeta function itself.

The largest value reported so far is π(1029), about 1.52 × 1027, computed in 2022 by Kim Walisch and David Baugh with a descendant of the combinatorial method. No list of those primes exists or could: there are far more of them than could ever be stored.

The Size of the Error

Switch between the raw error and the same error divided by √x/ln x, and watch a growing wander become a bounded one. Then turn on the random model and press New sample to compare the primes with chance.

0%scanned to x = 0
—
most extreme (π(x) − li(x))·ln x/√x from 100 to 0, at x = —
—
π(x) − li(x) at x = 0
yes
has π(x) reached li(x) in this range? Closest: — at x = —
—
most extreme for random sample 1, same scaling, at x = —
…
how the primes’ largest miss grew from 10³ to 10⁷
…
the random model’s largest miss
…
a fair coin’s largest miss (heads minus half the flips)
x0.82
x/ln² x over the same stretch
Raw, the error wanders and grows. Up to ten million li(x) is always too big, and by the end it overshoots by more than three hundred. But the count there is 664,579: the miss is in the fourth digit.
Is the error always this small: for every x, however large, no more than a fixed multiple of √x·ln x? That question is the Riemann hypothesis, in the form made precise in What the Hypothesis Says. It was open from 1859 until it was proved in November 2026, so the answer is yes. Nothing on this chart was ever evidence about large x: ten million is tiny, and π(x) does eventually overtake li(x), far beyond any range a computer has listed (See also: When Evidence Misleads).
the primes’ errorCramér’s random modela fair coin√xx/ln² x

Rose is the error, scanned at every whole number from 100 to ten million (the cap); each of the 600 columns of the chart shows the full range the error covers there, so no spike is lost. The −1 in the second view comes from the squares of primes: li(x) is the smooth count for the primes together with half of the prime squares, a third of the cubes and so on, and there are about 2√x/ln x prime squares up to x. Dashed slate is √x. Dashed teal is x/ln² x, the size of the gap between li(x) and x/ln x, which the prime number theorem in its simplest form, π(x) ~ x/ln x, cannot see below. In the random model (violet) 2 is called prime and each larger n is called prime with probability 1/ln n, independently, from a seeded generator; its typical miss is √(x/ln x). The pale line is a fair coin: heads minus half the number of flips. The growth exponents are read off two points of each curve, so the random ones change from sample to sample. All of this is double-precision arithmetic in your browser, not a proof of anything.

Go deeper:Square-Root Errors, Random Models and Littlewood’s Warning

Flip a fair coin N times and the number of heads misses N/2 by about √N. An error of square-root size is the signature of independent random choices. In 1936 Harald Cramér proposed modelling the primes the same way: call each n prime with probability 1/ln n, independently. The model’s count misses li(x) by about √(x/ln x), and the demo shows the true primes doing at least as well up to ten million. The model is a heuristic, and it is wrong in ways that matter. It knows nothing about divisibility: it happily makes n and n + 1 both prime. In 1985 Helmut Maier proved that in short intervals the real primes are distributed less evenly than the model predicts.

What had been proved about the error before 2026 was much weaker than a square root. De la Vallée Poussin showed in 1899 that π(x) − li(x) is at most a constant times x·e−c√(ln x) for some c > 0, which is smaller than x/(ln x)k for every k but larger than x0.999. Improvements since have only raised the power of ln x inside the exponential, from ½ to about ⅗: no bound of the form xθ with θ < 1 had ever been proved. In 1901 Helge von Koch showed that the Riemann hypothesis holds if and only if π(x) − li(x) is at most a constant times √x·ln x. That is the precise sense in which the question in the demo is the hypothesis, and since the hypothesis was proved in November 2026 the square-root bound is a theorem.

The −1 in the normalised chart is explained by Riemann’s R(x). The quantity that li(x) approximates without bias is not π(x) but π(x) + ½ π(x1/2) + ⅓ π(x1/3) + …, which counts a prime square as half a prime and a cube as a third. Solving for π(x) gives R(x), whose leading correction, −½ li(√x), is about −√x/ln x. Chebyshev’s ψ(x) counts the prime powers already, which is why its error is centred on zero.

Throughout the demo’s range, and for every x at which anyone has computed both, π(x) is less than li(x). Yet J. E. Littlewood proved in 1914 that the difference changes sign infinitely often. The fluctuations around −1 are sums of waves, and very occasionally enough of them reinforce one another to outweigh the bias. Evidence up to ten million, or ten trillion, says nothing about that. See also When Evidence Misleads.

Key Takeaways

  • Near x about one number in ln x is prime, and adding that density up gives li(x), Gauss’s smooth law for π(x).
  • The prime number theorem (1896) says the law is right in proportion; in Chebyshev’s weighting it reads ψ(x) ~ x.
  • π(x) can be computed far beyond any list of primes, using only about 2√x stored numbers.
  • Up to ten million the error behaves like √x; that it always does, up to a factor ln x, is the Riemann hypothesis, open for 167 years and proved in November 2026 (See also: What Is Actually Known).

Spot a mistake or have an idea?

Search