A computational tour of prime number gaps — from twin primes to jumping champions, computed across 5.7 million primes.
Prime numbers are distributed with deceptive irregularity. We know they thin out — the prime number theorem tells us the average gap near N is about ln(N) — but the individual gaps between consecutive primes hide a rich structure that defies simple description.
This is an exploration of that structure, computed across all 5,761,455 primes up to 100 million. Every chart below is drawn from real computed data, not approximations.
Not all gaps are created equal. The distribution is sharply peaked, with strong preferences for certain sizes. Here's the count of each gap size among our 5.7 million primes:
The pattern leaps out: gaps divisible by 6 dominate. Gap 6 is the most common, followed by 12, then 18, 24, 30... Why? Because all primes above 3 are congruent to 1 or 5 mod 6. A gap of 6 preserves this residue class, making it "easy" — while a gap of, say, 8 requires crossing from one residue class to the other, which is less likely.
Within the 6k pattern, there's a secondary structure: gaps of the form 6k tend to be more common than 6k±2. This is the fingerprint of the prime k-tuples conjecture at work — the number of admissible patterns of each gap size determines its frequency.
Twin primes (gap 2): 440,312. Cousin primes (gap 4): 440,257. A difference of just 55 out of nearly half a million. This near-equality is not a coincidence — Hardy and Littlewood's conjecture predicts they should have the same asymptotic density, since 2 and 4 each admit exactly one prime constellation pattern per period of 6.
The jumping champion at N is the most frequently occurring gap among primes up to N. For small primes, gap 2 (twin primes) dominates. But gap 6 overtakes it surprisingly quickly, and by our range, gap 6 is the clear champion with 75% more occurrences than gap 2.
Odlyzko, Rubinstein, and Wolf proved that 6 eventually overtakes 2 (which we see here), and conjectured that 30 will eventually overtake 6 — but not until around 1035, far beyond computational reach. The pattern is expected to continue: 30 yields to 210, yields to 2310, each being a primorial.
Let's widen the race. Here are the cumulative counts of gaps 2, 4, and 6 as we sweep through the primes:
Gaps 2 and 4 run in near-lockstep (that Hardy-Littlewood prediction again), while gap 6 pulls steadily ahead. The ratio gap(6)/gap(2) approaches the predicted asymptotic value from Hardy-Littlewood: the number of admissible 6-tuples vs 2-tuples gives a ratio approaching about 2.
A "record gap" (or maximal gap) is a gap larger than any that came before it. As primes thin out, new records appear — but increasingly rarely.
| Gap | After Prime | Merit |
|---|
In 1936, Harald Cramér conjectured that the largest gap below N grows like (ln N)2. This remains unproven, but we can test it empirically. The chart below plots the running maximum gap against (ln p)2:
The maximum gap stays well below (ln p)2 throughout our range, consistent with Cramér's conjecture. The ratio max_gap / (ln p)2 hovers around 0.6–0.7, matching the refined conjecture by Granville that the constant should be 2e−γ ≈ 1.1229, with our data still in the "early" regime where fluctuations keep it below 1.
The merit of a gap is gap / ln(p) — how large it is relative to what you'd expect. A merit above 1 means the gap is larger than average for that region. The current world record for gap merit is 39.0 (found computationally for enormous primes). Here are the merit records in our range:
| Gap | After Prime | Merit |
|---|
Every prime above 3 is either 1 mod 6 or 5 mod 6. Does the gap distribution differ depending on which class the starting prime belongs to?
The answer: dramatically yes. From p ≡ 1 (mod 6), the next prime can be at p+2 ≡ 3 (mod 6), p+4 ≡ 5 (mod 6), or p+6 ≡ 1 (mod 6). But p+2 ≡ 3 means it's divisible by 3 (unless it's literally 3), so gap 2 is suppressed from primes ≡ 1 (mod 6). Conversely, from p ≡ 5 (mod 6), p+2 ≡ 1 (mod 6) is fine, but p+4 ≡ 3 (mod 6) is divisible by 3. So gap 2 favors starts from 5 mod 6, and gap 4 favors starts from 1 mod 6. The distributions are mirror images, shaped by the simple constraint that no prime (except 3) is divisible by 3.
These patterns — the dominance of multiples of 6, the near-equality of gaps 2 and 4, the jumping champion transitions, the merit distribution — all emerge from a single source: the multiplicative structure of the integers. Primes avoid multiples of 2, 3, 5, 7, and this avoidance creates a "sieve" that shapes gap frequencies with mathematical precision.
The Hardy-Littlewood prime k-tuples conjecture gives exact predictions for all of these. The remarkable thing is how well those predictions match, even at the relatively modest scale of 108. The primes may look random, but their gaps are anything but.