Three ways to look at the same primes
This simulation shows the same underlying data — the sequence of primes — three different ways: an Ulam spiral, where integers are laid out in a square spiral and primes are lit up; a gap histogram, tallying how often consecutive primes differ by 2, 4, 6, and so on; and the counting function pi(n), which simply tracks how many primes exist up to n. Each view answers a different question about the same infinite, irregular set.
The Ulam spiral's diagonal lines
Stanislaw Ulam noticed the pattern by accident in 1963, doodling during a boring conference talk: write the integers in a square spiral starting from the center, mark the primes, and unmistakable diagonal lines emerge instead of the uniform scatter you'd expect from a "random" set. The explanation isn't mystical — every diagonal of the spiral corresponds to a quadratic polynomial an² + bn + c, and some quadratics are simply much better than others at avoiding small prime factors (a bias first studied by Hardy and Littlewood), so they produce a noticeably higher density of primes along that particular diagonal. The pattern is real, but it reflects known number-theoretic bias, not a new secret about the primes.
The Prime Number Theorem
Conjectured independently by Gauss and Legendre around 1800 from tables of primes, and finally proven in 1896 by Jacques Hadamard and Charles Jean de la Vallée Poussin, the Prime Number Theorem pins down how quickly primes thin out:
pi(n) = number of primes <= n
pi(n) ~ n / ln(n) as n -> infinity
(the ratio pi(n) / (n/ln(n)) tends to exactly 1)
n = 1,000 pi(n) = 168 n/ln(n) ≈ 145
n = 1,000,000 pi(n) = 78,498 n/ln(n) ≈ 72,382
Equivalently, a random integer near n has roughly a 1/ln(n) chance of being prime — around a 1-in-7 chance near a thousand, dropping to about 1-in-14 near a million. A tighter and more accurate approximation, the logarithmic integral Li(n), tracks pi(n) even more closely than n/ln(n) does, and the gap between the two is itself the subject of the still-unproven Riemann hypothesis.
Gaps: Bertrand's postulate and the twin primes
Between any two consecutive primes lies a gap, and on average that gap grows like ln(n) — consistent with the Prime Number Theorem, since primes near n occur with "probability" 1/ln(n). But gaps are far from uniform: Bertrand's postulate (1845, proven by Chebyshev in 1852) guarantees there's always a prime between any n > 1 and 2n, so gaps can never grow too fast relative to their location. At the other extreme, twin primes — pairs like (11, 13) or (17, 19) differing by exactly 2 — appear again and again no matter how far out you look, and the twin prime conjecture claims infinitely many such pairs exist, though this remains formally unproven.
A landmark partial result
In 2013, Yitang Zhang — then a relatively unknown lecturer — proved that there are infinitely many pairs of consecutive primes differing by at most 70 million, the first ever finite bound on prime gaps recurring infinitely often. Within months, the Polymath8 collaborative project drove that bound down to 246, where it currently stands. The gap of exactly 2 that the twin prime conjecture demands is still out of reach, but the qualitative question — do arbitrarily small gaps recur forever? — is now a proven yes, just not yet pinned to the smallest possible gap.
Frequently asked questions
Why do primes form diagonal lines on the Ulam spiral?
Because numbers on a given diagonal of the spiral all fit a quadratic formula an²+bn+c, and certain quadratics happen to produce a disproportionate share of primes for reasons tied to how often they avoid small prime factors. It is a visual accident of number-theoretic bias, not a hidden pattern in the primes themselves.
What does the Prime Number Theorem actually say?
That π(n), the count of primes up to n, is asymptotically n/ln(n) — the ratio π(n) / (n/ln(n)) tends to 1 as n grows. Equivalently, a random integer near n has roughly a 1/ln(n) chance of being prime, so primes thin out logarithmically, never vanishing but growing rarer forever.
Is the twin prime conjecture proven?
No, it remains open, but in 2013 Yitang Zhang proved that infinitely many consecutive primes differ by at most 70 million, and the Polymath project rapidly lowered that bound to 246. The gap of exactly 2 required by the twin prime conjecture is still unproven, but a fixed finite bound is now a theorem.
Try it live
Everything above runs in your browser — open Prime Distribution & Gaps and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Prime Distribution & Gaps simulation