Prime Number Checker
Check whether a whole number is prime, up to 100 digits, and see its smallest factor when it isn’t. Find the next or previous prime, the nth prime, or every prime in a range.
How to Use
- Choose Is it prime?, Next / previous, nth prime or List a range.
- Type a whole number of up to 100 digits. Commas are fine, and powers such as
2^31-1work too. - Read whether it is prime, its smallest prime factor and, up to 24 digits, the full factorisation. For every divisor and a factor tree, use the Prime Factorization Calculator.
- For a range, enter the first and last number: up to 1,000,000 numbers at a time, ending at most at 10¹². Ranges of 200 numbers or fewer are drawn as a grid, like the sieve of Eratosthenes.
- Show Work lists the trial divisions, the search for the next prime or the sieve, step by step.
Worked Example
Is 1,000,001 prime? Its square root is just over 1,000, so only the 168 primes below 1,000 need trying. The 26th of them, 101, divides it: 1,000,001 = 101 × 9,901, so it is not prime. (It is 10⁶ + 1, a sum of two cubes, 100³ + 1³, which always factors.)
Is 101 prime? √101 ≈ 10.05, so test 2, 3, 5 and 7. None divides 101, so it is prime, and with 103 it forms a twin prime pair.
The common mistake: “odd and not ending in 5” is not enough. 91 = 7 × 13, 133 = 7 × 19 and 561 = 3 × 11 × 17 all pass that check. 561 also fools Fermat’s test, aⁿ⁻¹ ≡ 1 (mod n), for every base a that shares no factor with it; the Miller–Rabin test used here catches it.
Show Work
Formulas
From Eratosthenes to Miller–Rabin
Euclid proved around 300 BC that the primes never run out. Later in the 3rd century BC, Eratosthenes of Cyrene described the sieve still used to list them: write the numbers out, then cross off the multiples of 2, 3, 5 and so on; what survives is prime. Around 1792 the teenage Carl Friedrich Gauss noticed that primes near n occur about once every ln n numbers. That became the prime number theorem, proved in 1896 by Jacques Hadamard and Charles de la Vallée Poussin independently.
Testing big numbers needed a different idea. Gary Miller (1976) and Michael Rabin (1980) built a test on Fermat’s little theorem that checks a 100-digit number in a fraction of a second, and in 2002 Agrawal, Kayal and Saxena showed primality can be proved in polynomial time. The record primes are Mersenne primes found by the volunteer GIMPS project; in October 2024 it found 2136,279,841 − 1, a number of 41,024,320 digits.
About This Tool
This checker answers questions about primes themselves. It tests any whole number up to 100 digits with the Miller–Rabin test (a proof below 3.3 × 10²⁴), gives the smallest factor and, up to 24 digits, the full factorisation, finds the next and previous primes, the nth prime up to the millionth (15,485,863), and lists every prime in a range of up to a million numbers with its twin pairs and density. To break a number into all its factors and divisors, the Prime Factorization Calculator goes further.
Everything runs in your browser; nothing is sent anywhere.
Related tools: Prime Factorization Calculator, GCF and LCM Calculator, and Big Number Calculator.
Frequently Asked Questions
Is 1 a prime number?
No. A prime has exactly two divisors, 1 and itself, and 1 has only one. Leaving 1 out keeps prime factorisations unique: if 1 counted, 6 could be 2 × 3 or 1 × 2 × 3 or 1 × 1 × 2 × 3. The smallest prime is 2, the only even one.
How do I check if a number is prime by hand?
Try dividing by the primes up to its square root; if none divides it, it is prime. For 101, √101 ≈ 10.05, so only 2, 3, 5 and 7 need testing, and none works. For 1,000,001 the limit is 1,000, and the 26th prime tried, 101, divides it: 1,000,001 = 101 × 9,901. Large numbers are tested with the Miller–Rabin method instead.
What are twin primes?
Two primes that differ by 2, such as 3 and 5, 11 and 13, or 101 and 103. There are 8 pairs below 100 and 8,169 below 1,000,000. Whether there are infinitely many is the unsolved twin prime conjecture; in 2013 Yitang Zhang proved that infinitely many prime pairs are less than 70 million apart, a bound since cut to 246.
What is a Mersenne prime?
A prime of the form 2ᵖ − 1. 2³¹ − 1 = 2,147,483,647, the largest 32-bit signed integer, was proved prime by Euler in 1772. The exponent must be prime, but that is not enough: 2¹¹ − 1 = 2,047 = 23 × 89. Most of the largest known primes are Mersenne primes, because they have a fast special test.
How many primes are there below a number?
About n ÷ ln n, by the prime number theorem. Below 100 that predicts 21.7 and there are 25; below 1,000,000 it predicts 72,382 and there are 78,498. The ratio tends to 1 as n grows. Near n, roughly one number in ln n is prime: about 1 in 14 near a million.
How do I use the Prime Number Checker?
Just type your numbers. The answer shows up right away — there is no button to press. Change anything and it updates by itself.
Do I need to install or sign up for anything?
Not at all — it runs in the browser with nothing to install and no account. After it loads once, it even works without an internet connection.
Is my information private?
Yes. Everything happens in your browser. Nothing you type is sent to a server or saved anywhere.
Common Use Cases
Programming contests
1,000,000,007 and 998,244,353 are both prime, which is why they are used as moduli.
Project Euler
Problem 7: the 10,001st prime is 104,743.
Hash tables
A prime table size near a million: the next prime after 1,000,000 is 1,000,003.
Homework
The 25 primes up to 100, highlighted on a 1–100 grid.
Spotting fakes
91 looks prime but is 7 × 13; 561 = 3 × 11 × 17 fools the Fermat test.
Last updated: