Skip to content
Calculator Collection

Prime Number Checker

Instantly determine whether any positive integer is a prime number. Use it for number-theory homework, cryptography exercises, and checking factors quickly.

Last updated: May 2026

Fill in the required fields to see your result.

Compare with similar

About this calculator

A prime number is an integer greater than 1 whose only positive divisors are 1 and itself; any integer greater than 1 that is not prime is composite. This checker uses trial division with the 6k ± 1 optimization. It first rules out 0, 1, and negatives as non-prime, treats 2 and 3 as prime, and eliminates any multiple of 2 or 3. After that, every prime greater than 3 has the form 6k − 1 or 6k + 1, so the algorithm tests only divisors of those forms, stepping i by 6 and checking i and i + 2. The loop runs while i·i ≤ n, because if n has a divisor larger than its square root it must also have a matching one smaller than the square root — so testing up to √n is sufficient. Here the single input is the number to check, and the result is 1 (prime) or 0 (not prime). Edge cases: n ≤ 1 returns 0 (1 is neither prime nor composite, by definition, to keep unique factorization valid), 2 is the only even prime, and large inputs remain fast because the work grows only with √n. Trial division is exact but slower than probabilistic tests for very large cryptographic primes.

How to use

Example 1 — is 17 prime? Enter Number to Check = 17. It is greater than 3, not divisible by 2 or 3, and the loop starts at i = 5; since 5·5 = 25 > 17, the loop body never runs, so no divisor is found and 17 is prime (result 1). Verify: 17 has no divisors other than 1 and 17. Example 2 — is 91 prime? Enter Number to Check = 91. It is not divisible by 2 or 3, so the loop checks i = 5 (91 / 5 is not whole) and i + 2 = 7; since 91 = 7 × 13, the test 91 mod 7 = 0 succeeds and the function returns 0 (not prime). Verify: 91 = 7 × 13, two factors other than 1 and 91, confirming it is composite. Note 91 is a classic 'looks prime but isn't' number.

Frequently asked questions

Is 1 a prime number?

No. By the modern definition a prime must be greater than 1, so 1 is neither prime nor composite. This is not an arbitrary choice: it preserves the Fundamental Theorem of Arithmetic, which says every integer above 1 has a unique prime factorization. If 1 were prime you could insert any number of 1s into a factorization and uniqueness would be lost. The number 1 is instead called a 'unit'. This calculator therefore returns 0 (not prime) for 1, as well as for 0 and negative numbers.

Why is it enough to check divisors only up to the square root?

Because divisors come in pairs that multiply to n: if d divides n then so does n/d, and one of each pair is always less than or equal to √n. So if no divisor exists at or below √n, none exists above it either, and the number is prime. Checking all the way to n would be correct but wastefully slow, especially for large inputs. This square-root bound is the key efficiency idea behind trial division. A common beginner mistake is testing divisors up to n/2 or n, which works but is far slower than necessary.

What is the 6k ± 1 optimization the checker uses?

After removing multiples of 2 and 3, every remaining integer — and therefore every prime greater than 3 — is of the form 6k − 1 or 6k + 1. The algorithm exploits this by starting at 5 and stepping by 6, testing i and i + 2 each time, which skips roughly two-thirds of candidate divisors. This makes trial division about three times faster than checking every odd number without changing the result. It is exact, not probabilistic, so it never gives false primes. The trade-off is that for very large numbers even this is slow compared with specialized primality tests.

Why does 91 fool people into thinking it is prime?

91 is odd, not divisible by 3 or 5, and ends in 1, so it superficially resembles many primes — but 91 = 7 × 13. The mistake is stopping the divisibility checks too early, particularly forgetting to test 7. Numbers that are products of two mid-sized primes are the classic traps in mental primality checks. The lesson is to test every prime up to the square root (here up to 9, so 2, 3, 5, 7) before declaring a number prime. This calculator avoids the trap by systematically checking all required divisors.

When should I NOT use this prime checker?

Avoid it for the very large numbers used in real cryptography (hundreds of digits), where exact trial division is far too slow; probabilistic tests like Miller–Rabin are used there instead. It is also the wrong tool if you need the actual factors of a composite number — use a prime-factorization calculator for that, since this one only returns prime or not. Do not apply it to non-integers or to 0, 1, and negatives expecting a meaningful 'prime' verdict; by definition those are not prime. Finally, if you need to generate many primes in a range, a sieve (like the Sieve of Eratosthenes) is more efficient than testing each number individually. Match the method to the size and goal of your problem.

Sources & references