Prime Number Calculator
Check whether any whole number is prime or composite using step-by-step square-root trial division, and see the nearest primes on either side of it.
How to use this calculator
Type any whole number from 0 up to 15 digits. The calculator tells you whether it is prime, composite, or neither, colour-codes the verdict, and — for a composite — shows its smallest prime factor. Underneath you get the square-root working and the nearest prime on each side.
What is a prime number?
A prime number is a whole number greater than 1 with exactly two distinct divisors: 1 and the number itself. 7 is prime because nothing between 1 and 7 divides it evenly. A number greater than 1 that has more than two divisors is composite — for instance , so 12 has the divisors 1, 2, 3, 4, 6, and 12.
Two whole numbers sit outside this split entirely: 0 and 1 are neither prime nor composite. 1 has only one divisor, so it fails the "exactly two" rule, and 0 is divisible by every integer.
Why 1 is not prime
It is tempting to call 1 prime, but the definition needs two different divisors. 1 divided by 1 is 1 — that is a single divisor, not two. Excluding 1 also keeps the Fundamental Theorem of Arithmetic clean: every integer greater than 1 has a unique prime factorization. If 1 counted as prime you could pad any factorization with extra 1s and uniqueness would break.
2 is the only even prime
Every even number is divisible by 2. For 2 itself that gives just the divisors 1 and 2 — exactly two — so 2 is prime. For any larger even number, 2 is a third divisor on top of 1 and the number, so it is automatically composite. That makes 2 the smallest prime and the only even one; every other prime is odd.
The square-root trial-division method
To test whether is prime, you only need to try dividing by the primes up to :
- Compute .
- List the primes that are less than or equal to .
- Divide by each of those primes.
- If none divides evenly, is prime. If one does, is composite.
Why the square root is the cut-off: divisors come in pairs . If both were larger than , their product would exceed — impossible. So every composite has a factor at or below ; finding just one is enough to declare it composite.
Worked example — is 417 prime?
- .
- Primes up to 20: 2, 3, 5, 7, 11, 13, 17, 19.
- (no); exactly.
- 3 divides 417, so 417 is composite: .
Very large numbers use the Miller–Rabin test
Trial division is fast for small numbers but slows down as values grow. For numbers beyond a trillion (), this calculator switches to the Miller–Rabin primality test — a fast, deterministic check (using fixed witness bases) that gives an exact prime-or-composite answer for every value up to the 15-digit limit, without listing a factor.
The 25 prime numbers below 100
There are exactly 25 primes below 100 (and 168 below 1000):
| The 25 primes below 100 | ||||
|---|---|---|---|---|
| 2 | 3 | 5 | 7 | 11 |
| 13 | 17 | 19 | 23 | 29 |
| 31 | 37 | 41 | 43 | 47 |
| 53 | 59 | 61 | 67 | 71 |
| 73 | 79 | 83 | 89 | 97 |
Prime numbers are the building blocks of every whole number (the Fundamental Theorem of Arithmetic) and the foundation of modern cryptography: multiplying two large primes is easy, but factoring their product back apart is extremely hard.
Frequently asked questions
- What is a prime number?
- A prime number is a whole number greater than 1 that has exactly two distinct divisors: 1 and itself. 2, 3, 5, 7, 11, and 13 are prime. A number greater than 1 with more than two divisors is composite — for example 6, whose divisors are 1, 2, 3, and 6.
- Is 1 a prime number?
- No. 1 has only a single divisor (itself), not the two required, so it is neither prime nor composite. 0 is also neither — it is divisible by every integer.
- Is 2 a prime number?
- Yes, and it is the only even prime. Every other even number is divisible by 2 in addition to 1 and itself, giving at least three divisors, so it is composite. That makes 2 the smallest prime and the only even one.
- Why does the check only test divisors up to the square root?
- If has a divisor larger than , it must pair with a divisor smaller than , because their product is . So if no prime up to divides , none larger does either, and is prime. Testing to the square root is enough.
- Is 417 a prime number?
- No. , and testing the primes up to 20 finds that exactly. Since 3 divides it, 417 is composite: .
- How are very large numbers checked?
- Numbers beyond a trillion () are too large to factor quickly by trial division, so the calculator uses the deterministic Miller–Rabin primality test. It returns a definite prime-or-composite verdict for every value up to the 15-digit limit.