Prime Number Checker
A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call
Free prime number checker. Find out instantly whether a number is prime (up to 24 digits), see a factor if it isn't, and get the nearest primes.
- A factor
- 0
- Previous prime
- 0
- Next prime
- 0
Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.
How to use the prime number checker
- Enter a whole number of 0 or more, up to 24 digits. You can paste numbers with commas or spaces; they're ignored.
- Read the result. The prime number checker tells you whether the number is prime. If it isn't, it shows a factor (when there's one under a million) so you can see why.
- See the nearest primes: the previous prime below the number and the next prime above it.
The check runs in your browser and gives an exact answer, not a probable one.
What is a prime number?
A prime number is a whole number greater than 1 that has exactly two factors: 1 and itself. It can't be divided evenly by any other whole number.
- Prime: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 …
- Not prime (composite): 4 (2 × 2), 6 (2 × 3), 9 (3 × 3), 91 (7 × 13), 100 (2 × 2 × 5 × 5).
Some special cases:
- 1 is not prime. It has only one factor. Excluding it keeps important theorems simple, such as the fact that every number has a unique prime factorization.
- 0 is not prime.
- 2 is the only even prime. Every other even number is divisible by 2.
How to check if a number is prime by hand
For small numbers, use trial division: try dividing by every prime up to the square root of the number. If none divides evenly, the number is prime.
To check 97: √97 ≈ 9.8, so try 2, 3, 5 and 7.
- 97 is odd (not divisible by 2)
- 9 + 7 = 16, not divisible by 3
- It doesn't end in 0 or 5
- 97 ÷ 7 = 13.86, not whole
So 97 is prime.
You only need to check up to the square root because if a number has a factor larger than its square root, it must also have one smaller than it.
Quick tests
- 2: the number is even.
- 3: the sum of its digits is divisible by 3.
- 5: it ends in 0 or 5.
- 7: double the last digit and subtract it from the rest; if the result is divisible by 7, so is the number (91: 9 − 2 = 7, so 91 is divisible by 7).
- 11: the alternating sum of its digits (first − second + third …) is divisible by 11.
How the prime number checker works
Trial division becomes slow for large numbers: checking a 20-digit number would need billions of divisions. The prime number checker uses the Miller–Rabin primality test instead.
Miller–Rabin is based on a property of primes from Fermat's little theorem. For a randomly chosen base, a composite number usually fails the test. In its usual form it's probabilistic, but mathematicians have proven that testing with the first 12 primes as bases (2, 3, 5, …, 37) gives a deterministic, exact answer for every number below about 3.3 × 10²⁴. That's why the checker accepts numbers up to 24 digits and gives a definite answer.
Interesting facts about primes
- There are infinitely many primes. Euclid proved this around 300 BC.
- Twin primes are pairs that differ by 2, such as 11 and 13 or 41 and 43. Nobody has proved whether there are infinitely many.
- Mersenne primes have the form 2ⁿ − 1, such as 7 and 31. The largest known primes are Mersenne primes with tens of millions of digits, found by the Great Internet Mersenne Prime Search (GIMPS).
- Primes thin out but never stop. Around a number n, roughly 1 in ln(n) numbers is prime (the prime number theorem). Near 1,000 that's about 1 in 7; near a billion, about 1 in 21.
- Every whole number above 1 is either prime or a unique product of primes. Our prime factorization calculator finds that product.
Why primes matter
Primes are the building blocks of whole numbers, and they're central to modern security. RSA encryption, used for secure websites and digital signatures, depends on the fact that multiplying two large primes is easy, but splitting the product back into its prime factors is extremely hard. Primes are also used in hashing, random number generators and error-correcting codes.
Prime numbers up to 100
There are 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
A classic way to list primes is the Sieve of Eratosthenes: write out the numbers, then cross out multiples of 2, then multiples of 3, then of 5, and so on. The numbers left are prime.
A worked example
Sam, a maths teacher, wants to check a few numbers for a quiz.
- 91: the prime number checker says it's not prime: 91 = 7 × 13. Many students guess it's prime because it's odd and doesn't end in 5.
- 1,000,000,007: prime. This prime is popular in programming contests, where answers are often given "modulo 10⁹ + 7".
- 561: not prime (561 = 3 × 187). It's the smallest Carmichael number, which fools the simpler Fermat primality test, a good example of why the checker uses Miller–Rabin.
- 1: neither prime nor composite.
Who uses a prime number checker
Students use it to check homework and explore number patterns. Teachers use it to create problems. Programmers use it to test algorithms and pick primes for hash tables. Puzzle fans and maths enthusiasts use it to explore primes and their patterns.
Need more customers from Google?
This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. DeepRit manages Google Ads for small and mid-size businesses, and only Google Ads. We check your account before we ever get on a call, then fix the structure, the keywords, the tracking and the ads, with month-to-month terms and no long contract. Book a free audit call.
Special kinds of primes
Mathematicians have named many families of primes:
- Twin primes: pairs differing by 2, such as (3, 5), (11, 13) and (59, 61).
- Cousin primes: pairs differing by 4, such as (7, 11).
- Sophie Germain primes: p is prime and 2p + 1 is also prime, such as 11 (23 is prime).
- Palindromic primes: read the same backwards, such as 131 and 757.
- Emirps: primes that become a different prime when reversed, such as 13 (31) and 17 (71).
- Mersenne primes: of the form 2ⁿ − 1, such as 31 and 127.
- Fermat primes: of the form 2^(2ⁿ) + 1; only five are known (3, 5, 17, 257 and 65,537).
Use the prime number checker to test candidates for any of these families.
Prime gaps
The gap between consecutive primes grows on average as numbers get larger, but irregularly. Below 100, the largest gap is 8 (between 89 and 97). Around a million, gaps of over 100 occur. The prime number checker's "previous prime" and "next prime" results show the gap around any number you enter.
Primes in programming
Programmers use primes in several practical ways:
- Hash tables: table sizes are often chosen as primes to spread values more evenly.
- Modular arithmetic: large primes such as 1,000,000,007 keep numbers manageable in calculations.
- Random number generators: some use prime moduli.
- Cryptography: RSA and other systems depend on large primes that are hundreds of digits long, far beyond this checker's 24-digit range; they use probabilistic tests with many rounds, which make errors astronomically unlikely.
Common misconceptions
- "All odd numbers are prime." No: 9, 15, 21, 25, 27 and many others are composite.
- "Numbers ending in 1, 3, 7 or 9 are prime." Not necessarily: 21, 33, 49 and 91 aren't.
- "1 is prime." It isn't, by definition.
- "There's a formula that produces all primes." No simple formula is known; primes are found by testing and sieving.
- "Large primes are rare." They thin out, but there are still infinitely many, and they're plentiful enough that computers can find hundred-digit primes quickly.
Primes in nature and culture
Some periodical cicadas emerge every 13 or 17 years, both prime numbers. One hypothesis is that prime cycles make it harder for predators with shorter cycles to synchronise with them. Primes also appear in music theory, art and fiction.
Sources and further reading
- Prime number on Wikipedia: definitions, properties and history.
- Miller–Rabin primality test on Wikipedia: how the test works and which bases make it deterministic.
- Great Internet Mersenne Prime Search, the project that finds the largest known primes.
Frequently asked questions
What is a prime number?
A whole number greater than 1 whose only factors are 1 and itself.
Is 1 a prime number?
No. A prime has exactly two factors, and 1 has only one.
Is 2 a prime number?
Yes. It's the only even prime.
How do I check if a large number is prime?
Use the prime number checker. It uses the Miller–Rabin test, which is exact for numbers up to 24 digits.
How many prime numbers are there below 100?
Is the prime number checker free?
Yes. It's free, needs no sign-up, and works in your browser.
Free PPC audit
See where your ad budget leaks.
We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.