How to use the prime number calculator
- Choose Test one number, List primes in a range or Find the nth prime.
- For a single number, enter any whole number from 1 to 1,000,000,000,000,000 (10^15).
- For a range, enter a start and an end up to 10,000,000. For the nth prime, enter a position up to 664,579.
- Read the verdict, prime factorization, number of divisors, sum of divisors and the next and previous primes, or the list and count of primes.
Formula
A prime has exactly two positive divisors: 1 and itself
Factorization by trial division on 2, 3 and numbers of the form 6k - 1 and 6k + 1
Number of divisors = product of (exponent + 1) over the prime factors
Sum of divisors = product of (1 + p + p^2 + ... + p^e) over the prime factors
Primality test: deterministic Miller-Rabin with the first 12 primes as bases
Using the first 12 primes as Miller-Rabin bases is exact for every number below about 3.3 x 10^24, far above this tool's limit. Lists and the nth prime come from a sieve of Eratosthenes up to 10 million.
Worked example
9,973 is prime, the next prime above it is 10,007 and the one below is 9,967.
360 factors as 2^3 x 3^2 x 5, so it has (3 + 1) x (2 + 1) x (1 + 1) = 24 divisors, and the divisors add up to 15 x 13 x 6 = 1,170.
There are 25 primes up to 100, the 1,000th prime is 7,919 and the 10,000th prime is 104,729. The large number 600,851,475,143 factors as 71 x 839 x 1,471 x 6,857.
What counts as prime
A prime number is a whole number greater than 1 whose only positive divisors are 1 and itself. The number 2 is the only even prime. The number 1 is neither prime nor composite, because it has only one positive divisor. Every whole number above 1 factors into primes in exactly one way, apart from order, which is why prime factorization is useful for finding greatest common factors and least common multiples with the GCF and LCM calculator.
How big can the numbers be
The single-number mode accepts values up to 10^15, which stays inside the range where JavaScript represents whole numbers exactly. Primality is tested with arithmetic on arbitrary-size integers, and factorization uses trial division, which finishes in a fraction of a second at that size. Range and nth-prime modes stop at 10 million so that the page stays fast and the list is easy to download as a CSV.
Tips
Short ways to speed up mental checks:
- A number is divisible by 3 if its digits add up to a multiple of 3.
- Any number ending in 0, 2, 4, 5, 6 or 8 other than 2 and 5 themselves is composite.
- To rule out a number n by hand, you only need to try primes up to the square root of n.
- For division practice with remainders, see the long division calculator.
Assumptions and limits
- Only whole numbers are accepted. Decimals, negatives and text are rejected with a message.
- The single-number limit is 10^15 and the range and nth-prime limit is 10,000,000.
- Lists on the page show the first 400 primes, and the CSV download contains every prime in the range.
- 1 is treated as neither prime nor composite, following the standard definition.
- Everything runs in your browser. Nothing you enter is sent anywhere.
Frequently asked questions
How do I check if a number is prime?
Enter it above. The tool tests it with a deterministic Miller-Rabin check and also shows the factorization, so a composite number comes with the primes that build it. By hand, divide by primes up to its square root.
Is 1 a prime number?
No. A prime needs exactly two different positive divisors, and 1 has only one. It is also not composite, so it sits in a category of its own.
What is the largest prime this calculator can test?
Single-number tests go up to 1,000,000,000,000,000 (10^15). Larger values exceed the range of exact whole numbers in the browser, so the tool refuses them instead of guessing.
How many primes are there below one million?
There are 78,498 primes below 1,000,000. The sieve in this tool counts exactly, and there are 664,579 primes below 10,000,000.
What is the nth prime?
It is the prime in position n when primes are listed in order: 2 is the 1st, 3 the 2nd, 5 the 3rd, and so on. For example, the 100th prime is 541.