Twin Prime Calculator - Find Prime Pairs in a Range

Every prime pair in your range.

Twin primes are two apart, cousin primes four apart and sexy primes six apart. Choose the pair type and a range, and the calculator sieves the whole window, lists each pair and compares the count with the Hardy–Littlewood prediction.

Whole numbers up to 10^12. Commas, 1e6 and 10^6 are all accepted.

At most 10,000,000 above the start. Both members of a pair must lie inside the range.

Numbers up to 1,000,000,000,000 (10¹²) and ranges up to 10,000,000 wide are supported; the list shows up to 3,000 pairs on screen and copies all of them.

Twin primes between 1 and 100

8

pairs (p, p + 2) with both primes inside the range

Primes in range

25

Twin primes

8

Cousin primes

8

Sexy primes

15

First pair: (3, 5)

Last pair: (71, 73)

Longest stretch without a pair: 18 numbers, from 41 to 59

Hardy–Littlewood prediction: about 13.5 twin pairs, so the real count is 59.1% of the estimate. The conjecture describes long ranges; for a short or low range the two numbers can differ a lot.

Where the pairs sit in this range

Pairs per tenth of the range. Bars are the pairs found; the dashed marks are the Hardy–Littlewood estimate for each tenth.

22101101001100
Pairs thin out roughly like 1/(ln x)², which is why long ranges starting near zero show a tall first bar.

The 8 twin prime pairs

  • (3, 5)
  • (5, 7)
  • (11, 13)
  • (17, 19)
  • (29, 31)
  • (41, 43)
  • (59, 61)
  • (71, 73)
How these pairs were found
  1. 1. Base primes. Any composite number up to 100 has a prime factor no larger than √10010, so only the 4 primes up to 10 are needed to cross out every composite in the range.
  2. 2. Segmented sieve. The window from 1 to 100 holds 100 numbers. Every multiple of each base prime inside it is crossed out (0 and 1 are never prime), leaving 25 primes, from 2 to 97.
  3. 3. Pair check. For each surviving prime p, the sieve is read at p + 2, p + 4 and p + 6. That gives 8 twin, 8 cousin and 15 sexy pairs whose larger member is still at or below 100.
  4. 4. Hardy–Littlewood estimate. 2 × C₂ × 1 × ∫ dt/(ln t)² = 2 × 0.660162 × 1 × 10.313.5, integrating from 2 to 100. The factor is 1 for twin and cousin pairs and 2 for sexy pairs, because a gap of 6 lets both primes share the same remainder on division by 3.

How to Use This Calculator

  1. Choose List every pair in a range for a full list and count, or Find the next pairs after a number when you only need the pairs just above one value, such as 10¹².
  2. Pick the Pair type: twin primes differ by 2, cousin primes by 4, sexy primes by 6. The three counts are always shown together; the type you pick decides which list is shown.
  3. Type the range ends or the starting number. Plain digits, thousands separators, 1e6 and 10^6 are all accepted; a range can be up to 10,000,000 wide and no number can exceed 10¹².
  4. Read the count, the primes in the range, the first and last pair and the longest pair-free stretch, then scroll the list. Copy all puts every pair on the clipboard, one per line, even when the screen shows only the first 3,000.
  5. Open How these pairs were found for the sieve details and the Hardy–Littlewood calculation, or load an example to see the layout with known answers.
average • 0 ratings
Your rating
Tap a star to rate

Your rating helps improve Twin Prime Calculator - Find Prime Pairs in a Range. We store only an anonymized vote (no personal data).

Share this calculator

Help others solve their calculations

Found this calculator helpful? Share it with your friends, students, or colleagues who might need it!

Twin Prime Calculator: Pairs That Keep Appearing No Matter How High You Look

About the Author

Marko Šinko - Co-Founder & Lead Developer

Marko Šinko

Co-Founder & Lead Developer, AI Math Calculator

Lepoglava, Croatia
Advanced Algorithm Expert

Croatian developer with a Computer Science degree from University of Zagreb and expertise in advanced algorithms. Co-founder of award-winning projects, ensuring precise mathematical computations and reliable calculator tools.

📅 Published:
Twin Prime Calculator illustration: a number line with bracketed pairs of neighbouring marks thinning out toward the right

Twin primes are two primes that differ by exactly 2, such as 11 and 13 or 101 and 103. There are 8 such pairs below 100, 35 below 1,000 and 8,169 below one million, and they never seem to stop: the largest pair anyone has found has 388,342 digits. This twin prime calculator lists every pair inside any range up to 10¹², counts the cousin pairs (gap 4) and sexy pairs (gap 6) in the same sweep, sets the count against the Hardy–Littlewood prediction, and can also jump straight to the first pairs after a number such as a billion.

Two conventions matter when you compare with a textbook. A pair only counts when both primes sit inside the range, so “cousin primes up to 100” gives 8 pairs and leaves out (97, 101). And the pair (2, 3) is not a twin pair, even though those primes are neighbours: twin means a difference of 2, and the only two primes 2 apart that share the number 5 are (3, 5) and (5, 7).

The Twin Primes List Up to 1,000 and the Pattern Inside It

Here are all 35 pairs with both members below 1,000, exactly as the calculator lists them:

(3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43), (59, 61), (71, 73), (101, 103), (107, 109), (137, 139), (149, 151), (179, 181), (191, 193), (197, 199), (227, 229), (239, 241), (269, 271), (281, 283), (311, 313), (347, 349), (419, 421), (431, 433), (461, 463), (521, 523), (569, 571), (599, 601), (617, 619), (641, 643), (659, 661), (809, 811), (821, 823), (827, 829), (857, 859), (881, 883)

Look at the number sitting between each pair: 6, 12, 18, 30, 42, 60, 72, 102, 108 and so on. From (5, 7) onward it is always a multiple of 6. The reason is short. Among any three consecutive whole numbers p, p + 1, p + 2, one is divisible by 3; if p and p + 2 are both primes above 3, the multiple of 3 must be the middle one, and it is also even because it sits between two odd numbers. So every twin pair above (3, 5) has the form (6n − 1, 6n + 1), which is why the calculator’s sieve only ever finds pairs straddling a multiple of 6. The same three-in-a-row argument shows why 5 is the only prime that belongs to two twin pairs: for (p, p + 2, p + 4) to be all prime, one of them must be 3 itself.

The list also shows how many primes are not twins. Below 100 there are 25 primes but only 15 of them belong to a twin pair; the other ten, namely 2, 23, 37, 47, 53, 67, 79, 83, 89 and 97, are called isolated primes. As the numbers grow the isolated primes take over. The table below is the calculator’s own output for ranges starting at 0; the prime counts match the nth prime calculator, which counts single primes rather than pairs.

Twin prime pairs with both members at or below 10ⁿ
Up toPrimesTwin pairsPrimes per twin pair
1002583.1
1,000168354.8
10,0001,2292056.0
100,0009,5921,2247.8
1,000,00078,4988,1699.6
10,000,000664,57958,98011.3

How the Twin Prime Calculator Finds Pairs in a Range Without Testing Every Number

Testing each number for primality one at a time, the way a prime calculator does for a single value, is the wrong tool for a range: a million-wide window would mean a million separate tests. A segmented sieve does the whole window at once. Take the range 1,000 to 1,100. Any composite number up to 1,100 has a prime factor no larger than √1,100 ≈ 33, so the only primes needed are the 11 primes from 2 to 31. Cross out every multiple of each of them inside the window, and the 16 survivors are the primes between 1,000 and 1,100:

1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097

Now read the pairs off the list. Neighbours that differ by 2 are (1019, 1021), (1031, 1033), (1049, 1051), (1061, 1063) and (1091, 1093): five twin pairs. Primes 4 apart give the cousin pairs (1009, 1013), (1087, 1091) and (1093, 1097), and primes 6 apart give five sexy pairs, (1013, 1019), (1033, 1039), (1063, 1069), (1087, 1093) and (1091, 1097). Notice that 1091 and 1093 belong to three different families at once, and that 1093 is famous in its own right as the smaller of the two known Wieferich primes.

Two details make this fast enough for a ten-million-wide window in well under a second. First, the base primes stop at the square root of the top of the range, so even at 10¹² only the 78,498 primes below one million are needed. Second, the first multiple of each base prime inside the window is found with a single remainder calculation rather than by walking up from zero, so a window near 10¹² costs the same as one near 0. Crossing out is the whole cost: a number that survives is prime because nothing divided it, so no primality test of any kind runs afterwards. For the factors of the numbers that were crossed out, the prime factorization calculator shows the full breakdown.

Cousin Primes and Sexy Primes: The Same Search With a Different Gap

Cousin primes differ by 4 and sexy primes by 6, the name being a pun on sex, the Latin word for six. The first cousin pairs are (3, 7), (7, 11), (13, 17) and (19, 23); the first sexy pairs are (5, 11), (7, 13), (11, 17) and (13, 19). Because the calculator reads all three gaps from the same sieve, switching the pair type never repeats the crossing-out, and the three counts appear side by side whichever list is open.

Pairs with both members at or below 10ⁿ, by gap
Up toTwin (gap 2)Cousin (gap 4)Sexy (gap 6)Sexy ÷ twin
10088151.88
1,0003541742.11
10,0002052034112.00
100,0001,2241,2162,4472.00
1,000,0008,1698,14416,3862.01
10,000,00058,98058,622117,2071.99

Twin and cousin pairs run neck and neck, while sexy pairs are almost exactly twice as common, and the reason is again division by 3. A prime above 3 leaves remainder 1 or 2 when divided by 3. For a twin pair, p and p + 2 must avoid remainder 0, which forces p to have remainder 2; the same squeeze applies to cousins, where p + 4 has the same remainder as p + 1. A gap of 6 changes nothing modulo 3, so p may have either remainder, and twice as many candidates survive. That factor of 2 is built into the Hardy–Littlewood estimate the calculator shows for sexy pairs.

The gap-6 family also produces longer chains than the others. Because 3 divides one of any three numbers spaced 4 apart, (3, 7, 11) is the only cousin triple, and 7 is the only prime in two cousin pairs. Sexy primes can form triplets like (7, 13, 19), quadruplets like (5, 11, 17, 23), and a single quintuplet, (5, 11, 17, 23, 29), which cannot be beaten because 5 divides one of any five numbers spaced 6 apart. Load the “Sexy primes to 100” example and the quadruplet appears as the three overlapping pairs (5, 11), (11, 17) and (17, 23).

How Many Twin Primes Are There? The Hardy–Littlewood Prediction

Nobody has proved that twin primes go on forever. What is known is a bounded-gap result: Yitang Zhang showed in 2013 that some fixed gap below 70 million occurs infinitely often, and the Polymath project brought that gap down to 246 the following year. From 246 to 2 is the distance that remains. What mathematicians do have is a remarkably accurate prediction of how many pairs there should be, the first Hardy–Littlewood conjecture:

π₂(x) ≈ 2C₂ ∫₂ˣ dt / (ln t)²      C₂ = 0.6601618158…

C₂ is the twin prime constant, the product over odd primes of 1 − 1/(p − 1)². The calculator evaluates the integral for whatever range you enter, so the estimate works for a window that starts at ten billion just as well as for one that starts at zero. Against the counts from the sieve, the estimate lands within 3% from 10,000 upward:

Twin pairs found versus the Hardy–Littlewood estimate
RangeFoundEstimateFound ÷ estimate
0 to 1,0003545.80.76
0 to 10,000205214.20.96
0 to 100,0001,2241,248.70.98
0 to 1,000,0008,1698,248.00.99
0 to 10,000,00058,98058,753.81.00
1,000,000 to 2,000,0006,7026,550.11.02
10¹² − 10⁶ to 10¹²1,7781,729.41.03

The last row is the “A million below 10¹²” example. That window holds 36,400 primes, and 1,778 of them start a twin pair, roughly one prime in twenty. The estimate is simply the density 2C₂/(ln x)² times the width: at 10¹², (ln x)² ≈ 763, so about 1.32/763 ≈ 0.0017 of all numbers, or 1,729 per million, begin a twin pair. The same density explains the bar chart under the calculator. In the first million, the tenths run 1,224, 936, 834, 810, 761, 766, 730, 705, 706, 697 pairs while the estimate runs 1,249, 933, 856, 811, 780, 756, 737, 722, 708, 697: the pairs thin out exactly as 1/(ln x)² says they should, slowly enough that even at 10¹² a million-wide window is still full of them.

Thinning out has a famous consequence. Viggo Brun proved in 1919 that the sum 1/3 + 1/5 + 1/5 + 1/7 + 1/11 + 1/13 + … over all twin primes converges, even though the corresponding sum over all primes does not. The limit, Brun’s constant, is about 1.902160583, and it is approached agonisingly slowly: the pairs below one million add up to 1.7108, the pairs below ten million to 1.7384, and every pair below 10¹⁶ still only reaches 1.8305. The published value comes from extrapolating that tail with the Hardy–Littlewood density, not from adding it up.

Droughts, Record Pairs and Searching Near Large Numbers

Averages hide the local swings, which is why the calculator reports the longest stretch without a pair. Below one million the record drought runs from the pair (850,349, 850,351) to (851,801, 851,803), 1,452 numbers apart with no twin pair between them, against an average spacing near there of about 150. Below ten million the record grows only to 1,722, and in the million-wide window under 10¹² it is 4,500, roughly eight times the average spacing of 580 in that region. The droughts grow, but far more slowly than the numbers do.

For a single large starting point, the next-pair mode is the better tool. The first twin pair after one billion is (1,000,000,007, 1,000,000,009), after 2³² it is (4,294,967,387, 4,294,967,389), and after 10¹² it is (1,000,000,000,061, 1,000,000,000,063), only 61 above the trillion. Beyond 10¹² the sieve would need base primes above a million and the method stops being instant, so the calculator stops there. Record-sized twin primes are found differently, by testing candidates of a special form; the current record, 2,996,863,034,895 × 2¹²⁹⁰⁰⁰⁰ ± 1 with 388,342 digits, was found in 2016 using the same kind of specialised primality proofs that the Mersenne prime calculator describes for numbers of the form 2ᵖ − 1.

Mistakes That Change the Count

  • Counting a pair that leans out of the range. “Sexy primes below 100” is 15 pairs, not 16, because (97, 103) reaches past 100. If you want pairs by their smaller member, extend the end of the range by the gap.
  • Treating (2, 3) as twin primes. They are consecutive primes, but consecutive is not the definition. Twin primes differ by 2, and 2 is the only even prime, so the first twin pair is (3, 5).
  • Expecting the Hardy–Littlewood estimate to be exact. It is an asymptotic density. Below 1,000 it overshoots by a quarter, and even in long ranges the found-to-estimate ratio wobbles by a few percent in both directions. A count that differs from the estimate is normal; a count that differs from the sieve is a mistake.
  • Assuming a mid-range prime is a twin because its neighbour is odd. Most primes are isolated. In the first million only 16,337 of the 78,498 primes belong to a twin pair, and every odd neighbour that is not prime is a composite number with an odd factor you can find in a second.

The sieve method, the (6n − 1, 6n + 1) form and the Hardy–Littlewood formula are laid out on Wolfram MathWorld’s twin primes reference page; Brun’s constant and its partial sums are documented under Brun’s theorem; and the bounded-gap results are Zhang’s Bounded gaps between primes (Annals of Mathematics, 2014) and the Polymath paper Variants of the Selberg sieve that reached 246. Every count in this article was produced by the calculator above and cross-checked against independent primality tests.

Frequently Asked Questions

What are twin primes?

Twin primes are two prime numbers that differ by exactly 2, such as (3, 5), (5, 7), (11, 13) and (17, 19). The pair (2, 3) does not count because its difference is 1. Below 100 there are 8 twin pairs, below 1,000 there are 35, and below one million there are 8,169.

How many twin primes are there below 1,000?

There are 35 twin prime pairs with both members below 1,000, from (3, 5) up to (881, 883). Continuing upward, there are 205 pairs below 10,000, 1,224 below 100,000, 8,169 below one million and 58,980 below ten million. The calculator produces these counts with a segmented sieve and lists every pair.

Are there infinitely many twin primes?

Nobody knows. The twin prime conjecture says yes, and the Hardy-Littlewood estimate predicts their numbers accurately as far as anyone has counted, but there is no proof. The closest result is bounded gaps: Yitang Zhang proved in 2013 that some gap below 70 million occurs infinitely often, and the Polymath project reduced that gap to 246 in 2014.

Why are all twin primes after (3, 5) of the form 6n - 1 and 6n + 1?

Among any three consecutive numbers p, p + 1 and p + 2, one is divisible by 3. If p and p + 2 are both primes above 3, the multiple of 3 must be the middle number p + 1, which is also even because it sits between two odd numbers. So p + 1 is a multiple of 6. That is why 11 and 13 sit either side of 12, and 101 and 103 either side of 102.

What is the difference between twin, cousin and sexy primes?

The gap. Twin primes differ by 2, cousin primes by 4, for example (7, 11) and (13, 17), and sexy primes by 6, for example (5, 11) and (7, 13); sexy comes from sex, the Latin word for six. Twin and cousin pairs are about equally common, while sexy pairs are roughly twice as common because a gap of 6 does not change the remainder on division by 3.

Is 5 the only prime that belongs to two twin prime pairs?

Yes. For a prime to be in two twin pairs, p, p + 2 and p + 4 would all have to be prime, but one of any three numbers spaced 2 apart is divisible by 3, so one of them must be 3 itself. That gives (3, 5, 7) as the only prime triplet of this shape, and 5 as the only prime shared by two twin pairs.

What is the largest known twin prime pair?

The largest known pair is 2996863034895 x 2^1290000 plus and minus 1, found in September 2016, with 388,342 decimal digits in each prime. Such records come from testing candidates of a special form with specialised primality proofs, not from sieving a range. This calculator handles ranges up to 10^12, where the segmented sieve is instant.

What does the Hardy-Littlewood prediction in the results mean?

It is the number of pairs the first Hardy-Littlewood conjecture expects in your range: 2 times the twin prime constant 0.66016 times the integral of 1/(ln t)^2 across the range, doubled for sexy primes. It is an asymptotic estimate, so below 1,000 it overshoots (45.8 predicted against 35 found) while from 10,000 upward it lands within about 3 percent of the sieve count.