How it works
A number greater than 1 is checked for any whole-number factor other than 1 and itself. If none exists, it is prime.
Take 97. The divisor 2 is ruled out at once because 97 is odd, and the remaining divisors below its square root of about 9.85 are 3, 5, 7 and 9. None divides 97 evenly: they leave remainders of 1, 2, 6 and 7 respectively. The next odd number to try would be 11, but 11 × 11 = 121 is already past 97, so the search stops there and the answer is prime. Stopping at the square root is what keeps the work short: a number in the tens of thousands needs a few dozen trials instead of a few thousand. The complementary question, which divisors a number does have, is answered by the Factors Calculator.
Primality concerns a single number, but the neighbouring question concerns a pair: what two numbers have in common. Because a prime number has only the factors 1 and itself, two different primes share nothing but 1, so their greatest common divisor is exactly 1. The GCD & LCM Calculator builds on that fact, and the guide to factors and primes sets primality and factorisation out together.
Formula: A prime number greater than 1 has no whole-number factors other than 1 and itself.
Examples
A prime number
17 is prime: no whole number between 2 and 16 divides evenly into it.
Not a prime number
18 is not prime: it divides evenly by 2, 3, 6 and 9, among others.
The only even prime
2 is prime: the only whole numbers that divide evenly into it are 1 and 2. Every even number above 2 is divisible by 2 and larger than 2, so it has a factor other than 1 and itself and is not prime.
A prime in the thousands
7919 is prime. No whole number below 89 divides evenly into it, and 89 × 89 = 7921 is already larger than 7919, so there is no larger factor left to find either.
Common uses
- Generating test data for a programming exercise that needs a whole number known to be prime.
- Checking a number quoted in a puzzle or a forum answer before you accept it.
- Narrowing a list of candidates down to the primes before choosing one as a modulus in a cryptography exercise.
Things to keep in mind
- 0, 1 and negative numbers are not prime — this is a definition, not an error, so the calculator simply answers "no" for them.
- 2 is the only even prime number; every other even number has 2 as a factor.
- Decimals are refused rather than rounded, because only whole numbers can be prime: 7.5 is not quietly turned into 7 or 8.
- Whole numbers up to 1,000,000,000,000 are checked exactly. A larger number is refused, because a trial-division search up to the square root would begin to slow the page noticeably.
- The result is a yes or a no rather than a number, so nothing is rounded: the check either holds exactly or the input is rejected.