Prime Number Calculator: Primality Tests, Prime Lists and Factorization
By FindMySum · Last reviewed
A prime number calculator answers four related questions: is this number prime, which primes lie below a limit, what is the nth prime, and what primes multiply together to make this number. A prime is a whole number greater than 1 whose only divisors are 1 and itself; every other whole number above 1 is composite and can be written as a product of primes in exactly one way. The methods behind each answer are old, mostly Greek, but the fast versions used here come from twentieth-century number theory. This article explains each method, runs the calculator's starting values through them, and shows how to read the result.
Testing one number
Trial division and the square-root bound
The direct way to test a number n is to try dividing it by smaller numbers. You only need to try divisors up to √n. If n = p × q and both factors were larger than √n, their product would be larger than n, which is impossible. So any composite number has at least one factor no bigger than its square root, and if none of the primes up to that point divides n, n is prime.
That is why the calculator reports a square-root bound with every check: it is the largest divisor a hand test would need. For 91, √91 is about 9.54, so the bound is 9 and only 2, 3, 5 and 7 need testing. The calculator finds that 7 divides 91 (91 = 7 × 13), so 91 is not prime, a number that catches many people out because it looks prime.
Why the calculator doesn't use trial division for big numbers
Trial division gets slow quickly. For a 16-digit number, the square root has 8 digits, and there are millions of primes below it. Instead, the calculator uses the Miller–Rabin test. It rests on a property of primes from Fermat's little theorem: for a prime p and any base a not divisible by p, raising a to the power p − 1 and taking the remainder after dividing by p always leaves 1. Composite numbers usually fail this test, and Miller–Rabin adds a stricter check that closes the loopholes.
Used with random bases, Miller–Rabin is probabilistic, which is how NIST's digital signature standard uses it to find primes hundreds of digits long for cryptographic keys. For numbers below a known size, though, a fixed set of bases is proven to give the right answer every time. Using the first 12 primes as bases is exact for every number the calculator accepts, so its "prime" verdict is a proof, not a probability.
Listing primes: the Sieve of Eratosthenes
To list every prime up to a limit, testing each number separately wastes effort. The sieve, credited to Eratosthenes of Cyrene in the third century BCE, works on the whole list at once: write out the numbers from 2 to the limit, keep the first unmarked number (2) and cross out all its multiples, then move to the next unmarked number (3) and do the same, and continue until you pass the square root of the limit. Whatever is left uncrossed is prime.
Two details make it efficient. Crossing out for each prime p can start at p², because smaller multiples were already removed by smaller primes. And you can stop once p² exceeds the limit. Up to 50, that means only 2, 3, 5 and 7 do any crossing out.
Prime factorization
Every whole number above 1 is a product of primes in a single way, apart from the order of the factors. This is the fundamental theorem of arithmetic, and it is the reason 1 is excluded from the primes: if 1 counted, you could add any number of 1s to a factorization and it would no longer be unique.
The calculator divides out small primes first, smallest to largest, repeating each one as long as it still divides. If a large cofactor remains, it splits it with Pollard's rho method, which finds a factor much faster than trying every possible divisor, and checks each piece with Miller–Rabin until only primes are left. The result is written with exponents, so 2 × 2 × 3 × 5 appears as 2² × 3 × 5.
Worked example: the calculator's starting values
The calculator opens in check mode with the number 7.
- The square-root bound is 2, since √7 is about 2.65.
- The only prime to try is 2, and 7 is odd.
- The calculator reports 7 is a prime number, divisible only by 1 and 7.
Switching operations loads a starting value for each one:
- List primes up to 50 gives 15 primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43 and 47.
- Nth prime with n = 10 gives 29, which you can confirm by counting along the list above.
- Factorize 60 shows the division steps 60 ÷ 2 = 30, 30 ÷ 2 = 15, 15 ÷ 3 = 5 and 5 ÷ 5 = 1, so 60 = 2² × 3 × 5.
The factorization tells you more than it seems. The number of divisors comes straight from the exponents: add 1 to each and multiply. For 60 that is (2 + 1) × (1 + 1) × (1 + 1) = 12 divisors: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30 and 60.
How common are primes?
Primes thin out as numbers grow. There are 15 below 50, 25 below 100 and 1,229 below 10,000, which the list mode reproduces. The prime number theorem says the count of primes up to x is roughly x divided by its natural logarithm. For 10,000 that estimate is about 1,086, an undercount of about 12%, and the relative error keeps shrinking for larger x. Put another way, near a number x, roughly one number in every ln x is prime: about one in 7 near 1,000 and about one in 37 near 10^16.
Limits of the calculator
It accepts whole numbers only, from 1 to 9,007,199,254,740,991 (2^53 − 1) for checks and factorizations. That ceiling is the largest whole number a browser stores exactly; beyond it, two different integers can share the same stored value and a primality verdict would be meaningless. It doesn't handle negative numbers, decimals, or the hundreds-of-digits numbers used in cryptography, which need arbitrary-precision software.
Using the result
Prime factorizations are the working tool behind fractions and multiples. The GCF and LCM calculator uses them to find common factors and common denominators, and the fraction calculator uses common factors to reduce answers to lowest terms. The exponent and logarithm calculator helps with numbers like 2^31 − 1 and with the natural logarithms in the prime number theorem, and the number system converter shows why such numbers are so tidy in binary: 2^31 − 1 is thirty-one 1s in a row.
More questions
Can 0 or a negative number be prime?
No. Primes are defined among the natural numbers greater than 1. Zero is divisible by every whole number, so it has infinitely many divisors, and negative numbers are left out of the definition by convention. In more advanced algebra, −7 is called an associate of 7, but for everyday use and in this calculator only whole numbers from 2 upward can be prime.
What does it mean for two numbers to be coprime?
Two numbers are coprime (or relatively prime) when their only common factor is 1, even if neither is prime. For example, 8 and 15 are coprime: 8 = 2³ and 15 = 3 × 5 share no prime factor. Factorizing both numbers here and comparing the factor lists is a quick way to check, and the GCF and LCM calculator gives the greatest common factor directly.
Are there quick tests for small divisors before I use the calculator?
Yes. A number is divisible by 2 if it ends in an even digit, by 3 if its digits add up to a multiple of 3, by 5 if it ends in 0 or 5, and by 11 if the alternating sum of its digits (first minus second plus third and so on) is a multiple of 11. For example, 2,145 has digit sum 12, so it is divisible by 3 and therefore not prime.
Why are the prime list and the nth prime limited?
The list stops at 10,000 (1,229 primes) and the nth prime at the 1,000th prime (7,919) so the page stays fast and the list stays readable on a phone. Checking a single number and factorizing go much further, up to 9,007,199,254,740,991, because those operations don't need to generate every prime below the number.
What is a Mersenne prime?
A Mersenne prime is a prime of the form 2^p − 1. The calculator confirms that 2^31 − 1 = 2,147,483,647 is prime, a result Leonhard Euler proved in 1772. Not every 2^p − 1 is prime, even when p is: 2^11 − 1 = 2,047 = 23 × 89. The largest primes known today are Mersenne primes, because there is an especially fast test for numbers of that shape.
Does a large number that isn't prime always have a small factor?
No, and that is what makes factorizing hard. The number 2^53 − 1, the largest the calculator accepts, factors as 6,361 × 69,431 × 20,394,401: its smallest factor is in the thousands, but the largest is over 20 million. Products of two large primes with no small factors at all are the basis of RSA encryption.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.