CalcSeed

Prime Number Checker

Enter a whole number to see whether it is prime, and find the next prime after it.

=
Quick answer: with the default inputs (29), the result is 31. Change any input to update the result.
Result
—

What this calculator does

Enter a whole number and the checker reports whether it is prime, then finds the next prime above it. At the default of 29 the verdict is a prime number and the next prime is 31. The method is trial division up to the square root, which stays fast for any input up to a billion.

What a prime number is

A prime is a whole number greater than 1 whose only divisors are 1 and itself. The number 29 qualifies; 30 does not, because 2, 3, 5, 6, 10 and 15 all divide it. A number with extra divisors is composite, and 1 is neither prime nor composite, a boundary case that shows up in every grading rubric.

nis prime⇔divisors(n)={1,n}n \text{ is prime} \Leftrightarrow \text{divisors}(n) = \{1, n\}

Worked example: testing 29

The square root of 29 is about 5.39, so only the primes 2, 3 and 5 need testing. Division by 2 fails because 29 is odd. Division by 3 gives 9 remainder 2. Division by 5 gives 5 remainder 4. No divisor up to the square root works, so 29 is prime. Scanning upward for the next one: 30 is even, so 31 is tested with the same three divisions, all of which fail — the next prime is 31, and the twin-prime gap here is just 2.

Why the square root is the stopping point

Divisors come in pairs that multiply to n: if d divides n, then n ÷ d does too, and one member of every pair is at most the square root. For 29 that limit is 5.39, so testing past 5 can only rediscover partners of divisors already checked. This is what makes trial division practical — a 10-digit number needs tests against roughly 3 million candidates rather than a quintillion, and skipping even numbers after 2 halves that again.

Primes and their next neighbors

PrimeNext primeGap
231
7114
13174
19234
29312
971014
9971,00912

Gaps widen slowly as numbers grow. Among the first hundred numbers the largest gap is 8, from 89 to 97, while near 1,000 the stretch from 887 to 907 spans 20. Twin primes like 29 and 31 keep appearing at every scale, and the distribution of these gaps is one of the open problems in number theory. The practical takeaway is that primes never run out — Euclid proved that more than two thousand years ago.

Special cases the definition forces

Three inputs behave unlike the rest. The number 1 has a single divisor and is classified as neither prime nor composite. The number 2 is the only even prime, since every other even number divides by 2. And any even number above 2 is instantly composite, which is why the checker tests 2 and then only odd candidates. Negative numbers and decimals sit outside the definition entirely.

Prime factorization in schoolwork

Classroom factor trees start from this same test. Split 60 into 2 × 30, then 30 into 2 × 15, then 15 into 3 × 5, and the leaves read 2, 2, 3 and 5 — the prime factorization 2² × 3 × 5. Each leaf had to survive a primality check, and from there the factor count formula (2+1) × (1+1) × (1+1) = 12 and the greatest common divisor with another number both fall out. Verifying that a candidate is prime is the step the whole tree depends on.

Why primes matter beyond homework

Every whole number above 1 factors into primes in exactly one way, which is why primes are called the atoms of arithmetic. Modern encryption stands on that structure: RSA-style systems in 2026 multiply two large primes to build a public key, and security rests on how hard it is to run the factorization backwards. A 2,048-bit key uses primes hundreds of digits long, and trial division would outlast the universe, which is why serious primality testing switches to faster algorithms at that scale.

Closer to daily life, primes explain why gear teeth counts are often prime (fewer resonance points), why hash tables pick prime sizes (keys spread more evenly), and why cicada broods with prime-year cycles of 13 and 17 years overlap rarely with predators’ cycles. The checker output is the same test at any of these scales.

Common mistakes

  • Calling 1 prime; it has only one divisor, and the definition demands exactly two
  • Assuming all odd numbers are prime; 9 = 3 × 3, 15 = 3 × 5 and 21 = 3 × 7 all fail
  • Testing past the square root; for 29 the check stops at 5, and every further division is wasted effort
  • Skipping 2; it is prime, and every other even number is composite by definition
  • Feeding decimals; this checker rounds to the nearest whole number, since primality applies to whole numbers only

The divisibility shortcuts catch most composite impostors without division at all: a number is divisible by 3 when its digit sum is (999 has digit sum 27, which is), by 5 when it ends in 0 or 5, and by 11 when the alternating digit sum is a multiple of 11. Running those checks first eliminates most candidates before trial division even starts.

Frequently asked questions

How do I check if 29 is prime?

Test every divisor up to its square root, about 5.39: only 2, 3 and 5 qualify. None divides it evenly (29 ÷ 3 leaves remainder 2, 29 ÷ 5 leaves 4), so 29 is prime.

Is 1 a prime number?

No. A prime needs exactly two distinct divisors, and 1 has only itself. It is classified as neither prime nor composite.

Is 2 prime?

Yes, and it is the only even prime. Every other even number divides by 2, which makes them composite by definition.

What is the next prime after 29?

31. The number 30 is even and fails immediately, while 31 survives the same three trial divisions as 29. They form a twin-prime pair 2 apart.

How far does this checker go?

Trial division handles inputs up to a billion. It tests 2, then odd numbers up to the square root, so a 9-digit input needs at most about 15,800 candidate divisions.

Why test only up to the square root?

Divisors pair up around the square root: any factor below it implies a partner above it. If no divisor exists up to √n, none exists at all.

What is the largest prime gap near small numbers?

Below 100 the widest gap is 8, between 89 and 97. Below 1,000 it is 20, between 887 and 907, and gaps keep growing slowly without bound.

How are primes used in encryption?

Public-key systems multiply two very large primes; recovering them from the product is computationally infeasible with known methods. That one-way difficulty is the security foundation of HTTPS and messaging apps in 2026.

Is 997 prime?

Yes. Its square root is about 31.6, and dividing by the primes 2 through 31 leaves a remainder every time. The next prime after it is 1,009, a gap of 12.

Method and sources

Calculation basis

Results follow exact mathematical definitions; the arithmetic is deterministic and can be verified by hand from the steps shown.

Last updated: November 17, 2026
Formula & data sources
  • Trial division up to sqrt(n) for primality testing.

Cite this page

Reference formats
APA 7CalcSeed. (2026, November 17). Prime Number Checker. https://calcseed.com/c/math/prime-number-checker/
MLA 9"Prime Number Checker." CalcSeed, 17 Nov. 2026, calcseed.com/c/math/prime-number-checker/.
ChicagoCalcSeed. "Prime Number Checker." Last modified November 17, 2026. https://calcseed.com/c/math/prime-number-checker/

Related calculators

More Math calculators

People also calculate