# Prime gap

A prime gap is the difference between two successive prime numbers. The n-th prime gap, denoted g$_n$ or g(p$_n$) is the difference between the (n + 1)-st and the n-th prime numbers, i.e.
    $g_{n}=p_{n+1}-p_{n}.\$
We have g$_1$ = 1, g$_2$ = g$_3$ = 2, and g$_4$ = 4. The sequence (g$_n$) of prime gaps has been extensively studied; however, many questions and conjectures remain unanswered.
The first 60 prime gaps are:
    1, 2, 2, 4, 2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4, 2, 4, 2, 4, 14, 4, 6, 2, 10, 2, 6, 6, 4, 6, 6, 2, 10, 2, 4, 2, 12, 12, 4, 2, 4, 6, 2, 10, 6, 6, 6, 2, 6, 4, 2, ... (sequence A001223 in the OEIS).
By the definition of g$_n$ every prime can be written as
    $p_{n+1}=2+\sum _{i=1}^{n}g_{i}.$

## Simple observations

The first, smallest, and only odd prime gap is the gap of size 1 between 2, the only even prime number, and 3, the first odd prime. All other prime gaps are even. There is only one pair of consecutive gaps having length 2: the gaps g$_2$ and g$_3$ between the primes 3, 5, and 7.
For any integer n, the factorial n! is the product of all positive integers up to and including n. Then in the sequence
    $n!+2,\;n!+3,\;\ldots ,\;n!+n$
the first term is divisible by 2, the second term is divisible by 3, and so on. Thus, this is a sequence of n − 1 consecutive composite integers, and it must belong to a gap between primes having length at least n. It follows that there are gaps between primes that are arbitrarily large, that is, for any integer N, there is an integer m with g$_m$ ≥ N.
However, prime gaps of n numbers can occur at numbers much smaller than n!. For instance, the first prime gap of size larger than 14 occurs between the primes 523 and 541, while 15! is the vastly larger number 1307674368000.
The average gap between primes increases as the natural logarithm of these primes, and therefore the ratio of the prime gap to the primes involved decreases (and is asymptotically zero). This is a consequence of the prime number theorem. From a heuristic view, we expect the probability that the ratio of the length of the gap to the natural logarithm is greater than or equal to a fixed positive number k to be e$^{−k}$; consequently the ratio can be arbitrarily large. Indeed, the ratio of the gap to the number of digits of the integers involved does increase without bound. This is a consequence of a result by Westzynthius.
In the opposite direction, the twin prime conjecture posits that g$_n$ = 2 for infinitely many integers n.

## Numerical results

Usually the ratio of g$_n$/ln⁡(p$_n$) {\textstyle {\frac {g_{n}}{\ln(p_{n})}}} is called the merit of the gap g$_n$. Informally, the merit of a gap g$_n$ can be thought of as the ratio of the size of the gap compared to the average prime gap sizes in the vicinity of p$_n$.
The largest known prime gap with identified probable prime gap ends has length 16,045,848, with 385,713-digit probable primes and merit M = 18.067, found by Andreas Höglund in March 2024. The largest known prime gap with identified proven primes as gap ends has length 1,113,106 and merit 25.90, with 18,662-digit primes found by P. Cami, M. Jansen and J. K. Andersen.
As of September 2022, the largest known merit value and first with merit over 40, as discovered by the Gapcoin network, is 41.93878373 with the 87-digit prime 2​9​3​7​0​3​2​3​4​0​6​8​0​2​2​5​9​0​1​5​8​7​2​3​7​6​6​1​0​4​4​1​9​4​6​3​4​2​5​7​0​9​0​7​5​5​7​4​8​1​1​7​6​2​0​9​8​5​8​8​7​9​8​2​1​7​8​9​5​7​2​8​8​5​8​6​7​6​7​2​8​1​4​3​2​2​7. The prime gap between it and the next prime is 8350.
Largest known merit values (as of October 2020) :
| Merit | g$_n$ | digits | p$_n$ | Date | Discoverer |
| 41.938784 | 08350 | 0087 | see above | 2017 | Gapcoin |
| 39.620154 | 15900 | 0175 | 3483347771 × 409#/0030 − 7016 | 2017 | Dana Jacobsen |
| 38.066960 | 18306 | 0209 | 0650094367 × 491#/2310 − 8936 | 2017 | Dana Jacobsen |
| 38.047893 | 35308 | 0404 | 0100054841 × 953#/0210 − 9670 | 2020 | Seth Troisi |
| 37.824126 | 08382 | 0097 | 0512950801 × 229#/5610 − 4138 | 2018 | Dana Jacobsen |
The Cramér–Shanks–Granville ratio is the ratio of g$_n$ / (ln(p$_n$))$^2$. If we discard anomalously high values of the ratio for the primes 2, 3, 7, then the greatest known value of this ratio is 0.9206386 for the prime 1693182318746371. Other record terms can be found at OEIS: A111943.
We say that g$_n$ is a maximal gap, if g$_m$ < g$_n$ for all m < n. As of October 2024, the largest known maximal prime gap has length 1676, found by Brian Kehrig. It is the 83rd maximal prime gap, and it occurs after the prime 20733746510561442863. Other record (maximal) gap sizes can be found in OEIS: A005250, with the corresponding primes p$_n$ in OEIS: A002386, and the values of n in OEIS: A005669. The sequence of maximal gaps up to the nth prime is conjectured to have about $2\ln n$ terms.
Gaps 1 to 28 :
| # | g$_n$ | p$_n$ |
| 1 | 1 | 2 |
| 2 | 2 | 3 |
| 3 | 4 | 7 |
| 4 | 6 | 23 |
| 5 | 8 | 89 |
| 6 | 14 | 113 |
| 7 | 18 | 523 |
| 8 | 20 | 887 |
| 9 | 22 | 1,129 |
| 10 | 34 | 1,327 |
| 11 | 36 | 9,551 |
| 12 | 44 | 15,683 |
| 13 | 52 | 19,609 |
| 14 | 72 | 31,397 |
| 15 | 86 | 155,921 |
| 16 | 96 | 360,653 |
| 17 | 112 | 370,261 |
| 18 | 114 | 492,113 |
| 19 | 118 | 1,349,533 |
| 20 | 132 | 1,357,201 |
| 21 | 148 | 2,010,733 |
| 22 | 154 | 4,652,353 |
| 23 | 180 | 17,051,707 |
| 24 | 210 | 20,831,323 |
| 25 | 220 | 47,326,693 |
| 26 | 222 | 122,164,747 |
| 27 | 234 | 189,695,659 |
| 28 | 248 | 191,912,783 |
Gaps 29 to 56 :
| # | g$_n$ | p$_n$ |
| 29 | 250 | 387,096,133 |
| 30 | 282 | 436,273,009 |
| 31 | 288 | 1,294,268,491 |
| 32 | 292 | 1,453,168,141 |
| 33 | 320 | 2,300,942,549 |
| 34 | 336 | 3,842,610,773 |
| 35 | 354 | 4,302,407,359 |
| 36 | 382 | 10,726,904,659 |
| 37 | 384 | 20,678,048,297 |
| 38 | 394 | 22,367,084,959 |
| 39 | 456 | 25,056,082,087 |
| 40 | 464 | 42,652,618,343 |
| 41 | 468 | 127,976,334,671 |
| 42 | 474 | 182,226,896,239 |
| 43 | 486 | 241,160,624,143 |
| 44 | 490 | 297,501,075,799 |
| 45 | 500 | 303,371,455,241 |
| 46 | 514 | 304,599,508,537 |
| 47 | 516 | 416,608,695,821 |
| 48 | 532 | 461,690,510,011 |
| 49 | 534 | 614,487,453,523 |
| 50 | 540 | 738,832,927,927 |
| 51 | 582 | 1,346,294,310,749 |
| 52 | 588 | 1,408,695,493,609 |
| 53 | 602 | 1,968,188,556,461 |
| 54 | 652 | 2,614,941,710,599 |
| 55 | 674 | 7,177,162,611,713 |
| 56 | 716 | 13,829,048,559,701 |
Gaps 57 to 83 :
| # | g$_n$ | p$_n$ |
| 57 | 766 | 19,581,334,192,423 |
| 58 | 778 | 42,842,283,925,351 |
| 59 | 804 | 90,874,329,411,493 |
| 60 | 806 | 171,231,342,420,521 |
| 61 | 906 | 218,209,405,436,543 |
| 62 | 916 | 1,189,459,969,825,483 |
| 63 | 924 | 1,686,994,940,955,803 |
| 64 | 1,132 | 1,693,182,318,746,371 |
| 65 | 1,184 | 43,841,547,845,541,059 |
| 66 | 1,198 | 55,350,776,431,903,243 |
| 67 | 1,220 | 80,873,624,627,234,849 |
| 68 | 1,224 | 203,986,478,517,455,989 |
| 69 | 1,248 | 218,034,721,194,214,273 |
| 70 | 1,272 | 305,405,826,521,087,869 |
| 71 | 1,328 | 352,521,223,451,364,323 |
| 72 | 1,356 | 401,429,925,999,153,707 |
| 73 | 1,370 | 418,032,645,936,712,127 |
| 74 | 1,442 | 804,212,830,686,677,669 |
| 75 | 1,476 | 1,425,172,824,437,699,411 |
| 76 | 1,488 | 5,733,241,593,241,196,731 |
| 77 | 1,510 | 6,787,988,999,657,777,797 |
| 78 | 1,526 | 15,570,628,755,536,096,243 |
| 79 | 1,530 | 17,678,654,157,568,189,057 |
| 80 | 1,550 | 18,361,375,334,787,046,697 |
| 81 | 1,552 | 18,470,057,946,260,698,231 |
| 82 | 1,572 | 18,571,673,432,051,830,099 |
| 83 | 1,676 | 20,733,746,510,561,442,863 |

## Further results
### Upper bounds

Bertrand's postulate, proven in 1852, states that there is always a prime number between k and 2k, so in particular p$_{n+1}$ < 2p$_n$, which means g$_n$ < p$_n$ .
The prime number theorem, proven in 1896, says that the average length of the gap between a prime p and the next prime will asymptotically approach ln(p), the natural logarithm of p, for sufficiently large primes. The actual length of the gap might be much more or less than this. However, one can deduce from the prime number theorem that the gaps get arbitrarily smaller in proportion to the primes: the quotient
    $\lim _{n\to \infty }{\frac {g_{n}}{p_{n}}}=0.$
In other words (by definition of a limit), for every $\epsilon >0$, there is a number $N$ such that for all $n>N$
    $g_{n}<p_{n}\epsilon$.
Hoheisel (1930) was the first to show a sublinear dependence; that there exists a constant θ < 1 such that
    $\pi (x+x^{\theta })-\pi (x)\sim {\frac {x^{\theta }}{\log(x)}}{\text{ as }}x\to \infty ,$
hence showing that
    $g_{n}<p_{n}^{\theta },$
for sufficiently large n.
Hoheisel obtained the possible value 32999/33000 for θ. This was improved to 249/250 by Heilbronn, and to θ = 3/4 + ε, for any ε > 0, by Chudakov.
A major improvement is due to Ingham, who showed that for some positive constant c,
    if $\zeta (1/2+it)=O(t^{c})$ then $\pi (x+x^{\theta })-\pi (x)\sim {\frac {x^{\theta }}{\log(x)}}$ for any $\theta >(1+4c)/(2+4c).$
Here, O refers to the big O notation, ζ denotes the Riemann zeta function and π the prime-counting function. Knowing that any c > 1/6 is admissible, one obtains that θ may be any number greater than 5/8.
An immediate consequence of Ingham's result is that there is always a prime number between n$^3$ and (n + 1)$^3$, if n is sufficiently large. The Lindelöf hypothesis would imply that Ingham's formula holds for c any positive number: but even this would not be enough to imply that there is a prime number between n$^2$ and (n + 1)$^2$ for n sufficiently large (see Legendre's conjecture). To verify this, a stronger result such as Cramér's conjecture would be needed.
Huxley in 1972 showed that one may choose θ = 7/12 = 0.583.
A result, due to Baker, Harman and Pintz in 2001, shows that θ may be taken to be 0.525.
The above describes limits on all gaps; another are of interest is the minimum gap size. The twin prime conjecture asserts that there are always more gaps of size 2, but remains unproven. In 2005, Daniel Goldston, János Pintz and Cem Yıldırım proved that
    $\liminf _{n\to \infty }{\frac {g_{n}}{\log p_{n}}}=0$
and 2 years later improved this to
    $\liminf _{n\to \infty }{\frac {g_{n}}{{\sqrt {\log p_{n}}}(\log \log p_{n})^{2}}}<\infty .$
In 2013, Yitang Zhang proved that
    $\liminf _{n\to \infty }g_{n}<7\cdot 10^{7},$
meaning that there are infinitely many gaps that do not exceed 70 million. A Polymath Project collaborative effort to optimize Zhang's bound managed to lower the bound to 4680 on July 20, 2013. In November 2013, James Maynard introduced a new refinement of the GPY sieve, allowing him to reduce the bound to 600 and also show that the gaps between primes m apart are bounded for all m. That is, for any m there exists a bound Δ$_m$ such that p$_{n+m}$ − p$_n$ ≤ Δ$_m$ for infinitely many n. Using Maynard's ideas, the Polymath project improved the bound to 246; assuming the Elliott–Halberstam conjecture and its generalized form, the bound has been reduced to 12 and 6, respectively.

### Lower bounds

In 1931, Erik Westzynthius proved that maximal prime gaps grow more than logarithmically. That is,
    $\limsup _{n\to \infty }{\frac {g_{n}}{\log p_{n}}}=\infty .$
In 1938, Robert Rankin proved the existence of a constant c > 0 such that the inequality
    $g_{n}>{\frac {c\ \log n\ \log \log n\ \log \log \log \log n}{(\log \log \log n)^{2}}}$
holds for infinitely many values of n, improving the results of Westzynthius and Paul Erdős. He later showed that one can take any constant c < e$^γ$, where γ is the Euler–Mascheroni constant. The value of the constant c was improved in 1997 to any value less than 2e$^γ$.
Paul Erdős offered a $10,000 prize for a proof or disproof that the constant c in the above inequality may be taken arbitrarily large. This was proved to be correct in 2014 by Ford–Green–Konyagin–Tao and, independently, James Maynard.
The result was further improved to
    $g_{n}>{\frac {c\ \log n\ \log \log n\ \log \log \log \log n}{\log \log \log n}}$
for infinitely many values of n by Ford–Green–Konyagin–Maynard–Tao.
In the spirit of Erdős' original prize, Terence Tao offered US$10,000 for a proof that c may be taken arbitrarily large in this inequality.
Lower bounds for chains of primes have also been determined.

## Conjectures about gaps between primes

As described above, the best proven bound on gap sizes is $g_{n}<p_{n}^{0.525}$ (for $n$ sufficiently large; we do not worry about $5-3>3^{0.525}$ or $29-23>23^{0.525}$), but it is observed that even maximal gaps are significantly smaller than that, leading to a plethora of unproven conjectures.
The first group hypothesize that the exponent can be reduced to $\theta =0.5$.
Legendre's conjecture that there always exists a prime between successive square numbers implies that $g_{n}=O({\sqrt {p_{n}}})$. Andrica's conjecture states that
    $g_{n}<2{\sqrt {p_{n}}}+1.$
Oppermann's conjecture makes the stronger claim that, for sufficiently large $n$ (probably $n>30$),
    $g_{n}<{\sqrt {p_{n}}}.$
All of these remain unproved. Harald Cramér came close, proving that the Riemann hypothesis implies the gap g$_n$ satisfies
    $g_{n}=O({\sqrt {p_{n}}}\log p_{n}),$
using the big O notation. (In fact this result needs only the weaker Lindelöf hypothesis, if one can tolerate an infinitesimally larger exponent.)
In the same article, he conjectured that the gaps are far smaller. Roughly speaking, Cramér's conjecture states that
    $g_{n}=O\!\left((\log p_{n})^{2}\right)\!,$
a polylogarithmic growth rate slower than any exponent $\theta >0$.
As this matches the observed growth rate of prime gaps, there are a number of similar conjectures. Firoozbakht's conjecture is slightly stronger, stating that $p_{n}^{1/n}\!$ is a strictly decreasing function of n, i.e.,
    $p_{n+1}^{1/(n+1)}\!<p_{n}^{1/n}{\text{ for all }}n\geq 1.$
If this conjecture were true, then $g_{n}<(\log p_{n})^{2}-\log p_{n}-1{\text{ for all }}n>9.$ It implies a strong form of Cramér's conjecture but is inconsistent with the heuristics of Granville and Pintz which suggest that $g_{n}>{\frac {2-\varepsilon }{e^{\gamma }}}(\log p_{n})^{2}>(1.1229-\varepsilon )(\log p_{n})^{2}$ infinitely often for any $\varepsilon >0,$ where $\gamma$ denotes the Euler–Mascheroni constant.
Polignac's conjecture states that every positive even number k occurs as a prime gap infinitely often. The case k = 2 is the twin prime conjecture. The conjecture has not yet been proven or disproven for any specific value of k, but the improvements on Zhang's result discussed above prove that it is true for at least one (currently unknown) value of k ≤ 246.

## As an arithmetic function

The gap g$_n$ between the nth and (n + 1)st prime numbers is an example of an arithmetic function. In this context it is usually denoted d$_n$ and called the prime difference function. The function is neither multiplicative nor additive.