Prime Gap Analyzer
Scans a user-defined range of integers, identifies all primes, and computes the gaps between consecutive primes including maximum, minimum, and average gap. Ideal for exploring prime distribution patterns.
About this calculator
A prime gap is the difference g = p_{n+1} − p_n between two consecutive prime numbers. The first gap is g = 1 (between 2 and 3); all subsequent gaps are even because primes greater than 2 are odd. The average gap near a large number N is approximately ln(N) by the Prime Number Theorem, which states that the number of primes up to N is approximately N / ln(N). Maximal gaps — the largest gaps seen up to a given point — grow roughly as (ln N)². Twin primes correspond to gaps of exactly 2, and their infinitude is an open conjecture. This calculator enumerates primes via trial division, then computes gap = primes[i+1] − primes[i] for each consecutive pair, reporting max, min, and mean gap statistics.
How to use
Set Start Range = 1 and End Range = 30. The primes found are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29. The consecutive gaps are: 1, 2, 2, 4, 2, 4, 2, 4, 6 — that is 9 gaps total. Maximum gap = 6 (between 23 and 29), minimum gap = 1 (between 2 and 3), average gap = (1+2+2+4+2+4+2+4+6)/9 ≈ 3.00. Enable 'Include Statistics' to see these summary values displayed alongside the gap list.
Frequently asked questions
What does the average prime gap tell you about prime distribution?
The average prime gap near N approximates ln(N) by the Prime Number Theorem. This means primes become sparser as numbers grow larger: near 1,000 the average gap is about 7, near 1,000,000 it rises to about 14. Analysing average gaps in a custom range lets you see this thinning empirically and compare it to the logarithmic prediction.
How do twin primes relate to prime gaps of size 2?
Twin primes are pairs of primes differing by exactly 2, such as (11, 13) or (17, 19). They correspond directly to gaps of size 2 in the gap sequence. The Twin Prime Conjecture posits that infinitely many such gaps exist, but this remains unproven. The Prime Gap Analyzer lets you count gaps of size 2 in any range, giving a concrete feel for twin prime density.
Why do all prime gaps beyond the first gap have to be even numbers?
Every prime greater than 2 is odd, because any even number greater than 2 is divisible by 2 and hence composite. The difference between two odd numbers is always even, so consecutive primes p_n and p_{n+1} (both odd for n ≥ 2) must have an even gap. The only odd prime gap is 1, occurring between the primes 2 and 3, since 2 is the unique even prime.