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.

Loading calculator…

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.

Tip: A quick shortcut: if a number ends in 0, 2, 4, 6, or 8 it is divisible by 2, and if its digits add up to a multiple of 3 it is divisible by 3 — so only 2 and 3 themselves are prime among such numbers.

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 12=2×6=3×412 = 2 \times 6 = 3 \times 4, 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 nn is prime, you only need to try dividing by the primes up to n\lfloor\sqrt{n}\rfloor:

  1. Compute n\sqrt{n}.
  2. List the primes that are less than or equal to n\sqrt{n}.
  3. Divide nn by each of those primes.
  4. If none divides evenly, nn is prime. If one does, nn is composite.

Why the square root is the cut-off: divisors come in pairs a×b=na \times b = n. If both were larger than n\sqrt{n}, their product would exceed nn — impossible. So every composite has a factor at or below n\sqrt{n}; finding just one is enough to declare it composite.

Worked example — is 417 prime?

  1. 41720.42\sqrt{417} \approx 20.42.
  2. Primes up to 20: 2, 3, 5, 7, 11, 13, 17, 19.
  3. 417÷2=208.5417 \div 2 = 208.5 (no); 417÷3=139417 \div 3 = 139 exactly.
  4. 3 divides 417, so 417 is composite: 417=3×139417 = 3 \times 139.

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 (101210^{12}), 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
235711
1317192329
3137414347
5359616771
7379838997

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 nn has a divisor larger than n\sqrt{n}, it must pair with a divisor smaller than n\sqrt{n}, because their product is nn. So if no prime up to n\lfloor\sqrt{n}\rfloor divides nn, none larger does either, and nn is prime. Testing to the square root is enough.
Is 417 a prime number?
No. 41720.42\sqrt{417} \approx 20.42, and testing the primes up to 20 finds that 417÷3=139417 \div 3 = 139 exactly. Since 3 divides it, 417 is composite: 417=3×139417 = 3 \times 139.
How are very large numbers checked?
Numbers beyond a trillion (101210^{12}) 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.

Related calculators