Prime Gaps — Definition, Formula & Examples
A prime gap is the difference between two consecutive prime numbers. For example, the gap between 11 and 13 is 2, while the gap between 23 and 29 is 6.
If denotes the -th prime number, the -th prime gap is defined as . For , every prime gap is even, since all primes beyond 2 are odd.
Key Formula
Where:
- = The n-th prime gap
- = The n-th prime number
- = The next consecutive prime after p_n
How It Works
To find a prime gap, identify two consecutive primes and subtract the smaller from the larger. The first gap is the only odd prime gap. After that, gaps are always even because consecutive primes greater than 2 are both odd. As numbers get larger, primes become sparser on average, so prime gaps tend to grow — but they grow slowly and irregularly. Pairs of primes with a gap of exactly 2 (like 11 and 13, or 41 and 43) are called twin primes. Whether infinitely many twin primes exist remains one of the most famous unsolved problems in mathematics.
Worked Example
Problem: Find all prime gaps for the primes between 1 and 30.
List the primes: The primes up to 30 are:
Compute each gap: Subtract each prime from the next consecutive prime:
Observe the pattern: The smallest gap after the first is 2 (twin primes: 3&5, 5&7, 11&13, 17&19). The largest gap in this range is 6, occurring between 23 and 29.
Answer: The prime gaps for consecutive primes up to 30 are: 1, 2, 2, 4, 2, 4, 2, 4, 6.
Visualization
Why It Matters
Prime gaps connect to active research in analytic number theory. Yitang Zhang's 2013 breakthrough proved that infinitely many prime pairs have a gap below 70 million — a finite bound that has since been reduced to 246. Understanding prime distribution also matters in cryptography, where algorithms like RSA depend on finding large primes that are sufficiently spaced apart.
Common Mistakes
Mistake: Assuming prime gaps grow steadily as numbers increase.
Correction: Prime gaps are highly irregular. Even among very large numbers, small gaps (like 2 or 6) still appear. The average gap near a prime p is approximately ln(p), but individual gaps fluctuate widely.
