What is a prime number checker?
A prime number is a whole number greater than 1 whose only divisors are 1 and itself: 2, 3, 5, 7, 11, 13 and so on. Every other number greater than 1 is composite and can be written, in exactly one way, as a product of primes (the Fundamental Theorem of Arithmetic). The number 1 is neither prime nor composite, and 2 is the only even prime.
This tool answers the questions people ask about a number: is it prime, what are its prime factors, what are all its divisors, which prime comes right before and right after it, and how many primes exist between two limits. It uses BigInt arithmetic, so results are exact for numbers of up to 20 digits, far beyond the 15 or so digits where ordinary JavaScript numbers start to lose precision. Primality is decided with a deterministic Miller-Rabin test with fixed bases, which is correct for the whole supported range, and factoring combines trial division with Pollard's rho for large numbers. Everything runs in your browser and nothing is uploaded.
The second tab lists every prime in a range, using the sieve of Eratosthenes, up to 2,000,000 numbers wide and ending at most at 1,000,000,000,000. It shows the exact count and a copyable list.
How to check if a number is prime and factor it
- Open "Check a number" and type a whole number. Dots, commas and spaces are accepted as thousands separators, so
1.000.000is read as 1000000. Signs and decimals are not accepted. - Read the verdict: "is a prime number", "is not prime (it is composite)" or "is neither prime nor composite" (for 0 and 1).
- Look at "Prime factors", written as a product with exponents, such as 2^3 × 3^2 × 5 for 360.
- See "Previous prime" and "Next prime", and the full list of divisors. When a number has more than 400 divisors the list is replaced by the factorization, which describes them all.
- For ranges, open "List primes in a range", fill "From" and "To" and read the exact count. Press "Copy list" to take the primes with you.
Examples
Is 97 prime?
Yes. Its only divisors are 1 and 97. The previous prime is 89 and the next is 101.
Factoring 91 and 561
91 = 7 × 13, so it is composite, even though many people guess it is prime. 561 = 3 × 11 × 17 is a Carmichael number: it fools the simple Fermat test, but this tool reports it as composite, with divisors 1, 3, 11, 17, 33, 51, 187 and 561.
A large number: 600851475143
It is composite: 71 × 839 × 1471 × 6857. It has 16 divisors, and the previous and next primes are 600851475067 and 600851475149. This is the number from Project Euler problem 3, whose largest prime factor is 6857.
Famous primes
2147483647 (2^31 − 1, the largest signed 32-bit integer) is prime, a Mersenne prime. 1000000007, popular in programming contests as a modulus, is prime, with 999999937 before it and 1000000009 after it.
Primes in a range
Between 1 and 50 there are 15 primes: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47. Between 1 and 100 there are 25, between 1 and 1000 there are 168 and between 1 and 1,000,000 there are 78,498.
Common mistakes
- Calling 1 a prime. By definition a prime has exactly two distinct divisors, and 1 has only one.
- Thinking every odd number is prime. 9, 15, 21, 91 and 561 are odd and composite. Check divisibility by 3, 5, 7 and 11 before guessing.
- Forgetting that 2 is prime. It is the only even prime; every other even number is divisible by 2.
- Typing a decimal or a sign.
1.5is read with the dot as a thousands separator and becomes 15, and-7is rejected. Only non-negative whole numbers make sense here. - Trusting a calculator that rounds. Ordinary floating-point numbers are exact only up to 2^53 (about 9 quadrillion); beyond that a plain calculator can give wrong factors. This tool uses exact integers.
- Testing very large numbers with big prime factors. If a number has huge prime factors, splitting it may take too long. The tool says so, and the primality verdict above is still exact.
Frequently asked questions
How do I know if a number is prime?
Try dividing it by the primes up to its square root. If none divides it, it is prime. For large numbers, use a primality test such as Miller-Rabin, as this tool does.
Is 0 prime? And 1?
No. Neither is prime nor composite.
How many primes are there?
Infinitely many, as Euclid proved around 300 BC. They get rarer: about 1 in 7 numbers near 1,000 is prime, and there are 168 primes below 1,000.
What is the largest prime this tool can handle?
Any number of up to 20 digits is tested exactly. Larger primes, such as the Mersenne primes with millions of digits, need specialized software.
How do I find the greatest common divisor of two numbers?
Compare their prime factors, or use the GCD and LCM calculator. For arithmetic expressions with large numbers use the math evaluator.
Prime numbers in code
JavaScript
const isPrime = n => {
if (n < 2) return false;
for (let d = 2; d * d <= n; d++) if (n % d === 0) return false;
return true;
};
console.log(isPrime(97), isPrime(91)); // true falsePython
def factorize(n):
out, d = {}, 2
while d * d <= n:
while n % d == 0:
out[d] = out.get(d, 0) + 1
n //= d
d += 1
if n > 1: out[n] = out.get(n, 0) + 1
return out
print(factorize(360)) # {2: 3, 3: 2, 5: 1}Bash
factor 600851475143 # GNU coreutils: 600851475143: 71 839 1471 6857