Prime Gap Calculator
Enter a number to see its surrounding primes and the prime gap.
Result
How it is calculated
For a whole number n, the tool looks for the nearest prime strictly below it, p, and the nearest prime strictly above it, q, then reports gap = q − p. Each candidate is tested by trial division: even numbers other than 2 are rejected, and odd divisors are tried up to the square root of the candidate. The search moves down from n − 1 and up from n + 1 one step at a time. Accepted inputs are whole numbers from 3 to 1,000,000,000; decimals, numbers below 3 and numbers above the limit give no result. If n is itself prime, it is skipped, so the gap spans across it and equals the sum of two consecutive prime gaps.
Worked example
Take n = 114. Going down: 113 is prime (not divisible by 2, 3, 5 or 7, and 11 is already above its square root, which is about 10.6), so the previous prime is 113. Going up: 115 = 5 × 23, 116 and 118 are even, 117 = 9 × 13, 119 = 7 × 17, 120 is even, 121 = 11 × 11, 122 and 124 and 126 are even, 123 = 3 × 41, 125 = 5³, and 127 is prime. The next prime is 127, so the gap is 127 − 113 = 14.
Common mistakes
- Entering a prime and expecting its own gap to the next prime. A prime input is skipped, so 113 returns 109 and 127 with a gap of 18, not the 14 between 113 and 127.
- Reading the gap as the count of composite numbers in between. The gap is the difference of the two primes, so 113 and 127 have 13 numbers between them, not 14.
- Typing a number with decimals, a negative or 2 and expecting an answer. Only whole numbers from 3 up to one billion are accepted.
- Assuming the result is the next prime after a prime-looking number. Numbers such as 91 look prime but are not, so the tool checks them properly and 91 is not treated as a neighbour prime.
About this calculator
A prime gap is simply the distance between one prime number and the next one along the number line. This calculator finds the largest prime below your chosen number and the smallest prime above it, then reports the gap between those two neighbors, letting you see how prime numbers thin out or cluster around any point you pick.
Prime gaps are famously irregular: the Prime Number Theorem tells us that on average, gaps near a number n grow roughly in proportion to the natural logarithm of n, so primes get sparser as numbers get bigger. But locally, gaps swing wildly — twin primes sit only 2 apart, while long stretches of consecutive composite numbers can create gaps of thousands. Whether every gap of size 2 recurs forever is the famous unsolved twin prime conjecture, and the general behavior of gaps is a major topic in analytic number theory and computational searches for record-sized gaps.
Students use tools like this to build intuition about prime distribution, and programmers and cryptographers use similar logic when picking candidate primes for keys, where knowing the neighborhood of primes around a starting point matters.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments