Math calculator

Prime Number Calculator

Whether a number is prime, with a divisor named when it is not.

Is it prime?

With the reason, not just the verdict.

A whole number up to twenty-five digits.

97

Prime

97 is prime.

Divisor found

none

nothing below the square root divides it

Searched to

9

4 primes in that range

Previous prime

89

a gap of 8

Next prime

101

not a twin

The 6k ± 1 shape

97 = 6 × 16 + 1

Every prime above 3 sits one away from a multiple of 6, because 6k, 6k ± 2 and 6k + 3 are all divisible by 2 or 3. A search can therefore skip five numbers in every six.

Named shapes

  • Congruent to 1 mod 4, so it is the sum of two squares in exactly one way — a theorem of Fermat.
  • Nothing up to 9 divides 97, and there are 4 primes in that range. The square root is far enough: two factors both larger than it would multiply to more than the number, so if any factor existed, one would have turned up below the root.
  • The test used here is deterministic, not probabilistic — the witness set is proven correct for every number below 3.3 × 10²⁴, which is far past anything typed by hand. So this says prime, not probably prime.
  • Every prime above 3 is one away from a multiple of 6. Numbers of the form 6k, 6k ± 2 and 6k + 3 are divisible by 2 or 3, which leaves only 6k ± 1 — so a search can skip five numbers in every six.

Deterministic test, not probabilistic — the witness set is proven correct far past anything typed here.

What this tool shows

A composite answer comes with a divisor you can check yourself. A prime answer says how far the search went and how many primes that ruled out. The test is deterministic, not a probability.

  • Whether the number is prime
  • A divisor, when it is not
  • How far the search had to go, and how many primes that was
  • The nearest prime on either side, and the gap
  • Twin primes, and the 6k ± 1 shape
  • Mersenne and Fermat primes, when they apply
A divisor named, not just a verdict Deterministic, not probabilistic Nearest primes and the gap Mersenne and Fermat shapes flagged

Deterministic test; the witness set is proven correct.

Updated 7 September 2026 · Works in any browser, no installation

A prime has exactly two distinct factors: 1 and itself. To check by hand, try dividing by each prime up to the square root — if none of them divides it, nothing does, because two factors both above the square root would multiply to more than the number. 97 needs only 2, 3, 5 and 7 tried. 91 fails at 7, and 7 × 13 is the proof.

At a glance

Formula shown
n is prime when it has exactly two distinct positive divisors. Trial division to \u221an decides it, because two factors both above \u221an would multiply to more than n. This page uses a deterministic Miller-Rabin whose witness set is proven correct below 3.3 \u00d7 10\u00b2\u2074.
Scenario support
Checking a candidate before using it as a modulus; verifying a puzzle answer; settling whether a number that looks prime actually is.
Educational estimate
Planning support from the values you enter — not professional advice.

How primality is decided

The schoolbook method is trial division: try every prime up to the square root. It is exact, and it is what the page runs on smaller numbers to find a divisor when one exists.

Past a certain size it becomes slow, and the standard replacement is the Miller-Rabin test. Used with random witnesses it is probabilistic. Used with a FIXED set of small witnesses it is provably exact below a known bound — the twelve primes up to 37 settle every number below 3.3 × 10²⁴.

That is the version here, and it is why this page says “prime” rather than “probably prime”. The limit of twenty-five digits sits well inside the proven range.

Why 1 is not prime

The definition asks for exactly TWO distinct factors. 1 has one. That is the whole reason, and it is a count rather than a convention.

There is a deeper cost to including it. Unique factorisation says every number above 1 is a product of primes in exactly one way. If 1 were prime, 12 could be 2 × 2 × 3, or 1 × 2 × 2 × 3, or with any number of 1s — and the theorem that makes primes useful would need a clause bolted on.

1 was in fact called prime by some mathematicians into the early twentieth century. It stopped because keeping it cost more than it was worth.

The 6k ± 1 shape

Every prime above 3 is one away from a multiple of six. Not a coincidence: of the six residues modulo 6, four are immediately disqualified.

6k is divisible by 6. 6k + 2 and 6k + 4 are even. 6k + 3 is divisible by 3. That leaves only 6k + 1 and 6k − 1, and every prime above 3 must be one of them.

It is a real speed-up for a hand search, since it lets you skip five numbers in every six. It is not a test for primality — 25 and 35 are both of that shape and neither is prime — it only narrows where to look.

Carmichael numbers, and why the test is deterministic

Fermat’s little theorem gives a quick test: if n is prime then a^(n−1) leaves remainder 1 modulo n for any a not divisible by n. Composite numbers usually fail it, so it looks like a cheap primality check.

Carmichael numbers pass it for every a coprime to them while being thoroughly composite. 561 is the smallest — it is 3 × 11 × 17 — and there are infinitely many.

Miller-Rabin closes the hole by looking at the square roots of 1 along the way rather than only the endpoint, and no composite survives it against the fixed witness set below the proven bound. Enter 561 above and it is correctly rejected, with 3 named as the divisor.

Gaps, twins and how primes thin out

Primes get rarer as numbers grow. Around n, roughly one number in ln(n) is prime — about one in seven near 1000, one in twenty near 500 million.

They still cluster. Twin primes, two apart, keep appearing as far as anyone has looked, and whether they do so forever is one of the oldest open questions in mathematics. This page says when your number is one of a twin pair.

Gaps can also be made arbitrarily long: the numbers from n! + 2 to n! + n are all composite, which gives a run of n − 1 with no prime in it. Both facts are true at once, which is what makes the distribution interesting.

Why anyone needs large primes

RSA encryption picks two large primes, multiplies them, and publishes the product. Anyone can multiply; nobody can factorise a six-hundred-digit product back into its two primes in any reasonable time.

Notice what that requires: primality must be EASY to check and factorisation must be HARD. Both are true, and the gap between them is the entire foundation. Miller-Rabin is what makes the first half work at that scale.

Hash tables use primes for a smaller reason — a prime table size spreads keys more evenly, because a key pattern sharing a factor with the size collides systematically.

Sources and methodology

Deterministic Miller-Rabin bounds are a published result; these are the references.

Method. A deterministic Miller-Rabin test with the twelve-witness set that is proven to give the exact answer for every number below 3.3 × 10²⁴ — far past the twenty-five digit limit this page accepts. That is why the verdict is stated as prime rather than probably prime. When the answer is composite and the number is small enough, trial division runs alongside to find the smallest divisor, because a named witness is a proof the reader can check and a bare verdict is not. That engine is verified on every change against 64 hand-written assertions, including that the test agrees with plain trial division on every number under thirty thousand, and that it correctly rejects the Carmichael numbers that defeat the naive Fermat test. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Prime FactorizationBreak any number into primes with the division ladder shown, the number of trial divisions reported, and the argument for why the search can stop at the square root.
FactorEvery factor of a number listed in the pairs that generate them, with the count derived from the prime exponents and separately checked against the list.
Divisibility TestEvery divisibility rule from 2 to 16 applied to your number, each with its working, the reason it holds, and the true remainder beside it as a check.
GCFThe greatest common factor of two to six numbers with all three routes shown — the shared primes to their lower powers, Euclid line by line, and the full factor lists when they are short enough to be honest.
LCMThe least common multiple of two to six numbers, with the prime table that produces it, the multiples themselves, and how far counting would have had to go.
Binomial Coefficientn choose k exactly on big integers, by the multiplicative formula that divides as it goes and never builds a factorial — with Pascal's rule and permutations beside it.

More in Math, or browse all calculators.

Read the guide

If the answer is no and you want the full breakdown, the Prime Factorization Calculator gives every prime with its power. If you want everything that divides the number rather than just the primes, the Factor Calculator lists them in pairs.

Educational use disclaimer

This is an educational tool. The primality test is deterministic and proven correct far past the twenty-five digit limit this page accepts, so the verdict is exact rather than probabilistic.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 7 September 2026

  1. Published the prime page: a composite answer names a divisor, because 'composite' on its own is an assertion while 91 = 7 × 13 is a proof anyone can check.
  2. The test is deterministic Miller-Rabin with the twelve-witness set proven correct below 3.3e24, so the page says prime rather than probably prime and can defend it.
  3. Carmichael numbers, which defeat the naive Fermat test, are correctly rejected — 561 is a preset for exactly that reason.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.