Prime Factorization Calculator
Prime factors with division steps, a factor tree, the divisor count and every divisor.
Enter a whole number to check if it is prime, or switch to List primes in a range to get every prime number between two limits.
Is 9973 prime?
Prime
9973 has no divisors other than 1 and itself.
9973 is a prime number. The nearest primes are 9967 and 10,007.
| Prime p | Remainder | Divides? |
|---|---|---|
| 2 | 1 | No |
| 3 | 1 | No |
| 5 | 3 | No |
| 7 | 5 | No |
| 11 | 7 | No |
| 13 | 2 | No |
| 17 | 11 | No |
| 19 | 17 | No |
| 23 | 14 | No |
| 29 | 26 | No |
| 31 | 22 | No |
| 37 | 20 | No |
| 41 | 10 | No |
| 43 | 40 | No |
| 47 | 9 | No |
| 53 | 9 | No |
| 59 | 2 | No |
| 61 | 30 | No |
| 67 | 57 | No |
| 71 | 33 | No |
| 73 | 45 | No |
| 79 | 19 | No |
| 83 | 13 | No |
| 89 | 5 | No |
| 97 | 79 | No |
Find how far to search
If 9973 had a factor other than 1 and itself, one factor would be at most √9973 ≈ 99.86. So only the primes up to 99 need testing.
Divide by each prime
None of the 25 primes from 2 to 97 divides 9973: every remainder is non-zero (see the table).
Conclusion: prime
9973 has no prime factor up to its square root, so its only divisors are 1 and 9973.
There are 25 primes from 1 to 100 and 168 below 1,000. Small numbers are tested by trial division up to , large ones by the Miller–Rabin test, and a composite answer shows its smallest prime factor.
Definition of a prime
Plain-text formula: p > 1 is prime ⇔ its only positive divisors are 1 and p
A whole number greater than 1 that is not prime is composite. The numbers 0 and 1 are neither.
Trial division bound
Plain-text formula: n = ab, 1 < a ≤ b ⇒ a ≤ √(n)
If n has a factorization into two factors greater than 1, the smaller one is at most √n. So testing the primes up to √n is enough, and the same bound tells the sieve when to stop.
Miller–Rabin test
Plain-text formula: n − 1 = 2^s d, a^d ≡ 1 or a^(2^r d) ≡ −1 (mod n) for some 0 ≤ r < s
Every odd prime satisfies this for every base a. A composite number fails it for at least three quarters of the bases, and below the 13 prime bases 2 to 41 always expose it.
Prime number theorem
Plain-text formula: π(n) ≈ n/(ln n)
π(n) counts the primes up to n. From n = 17 upward the estimate is always a little low: π(1,000) = 168, while 1,000 / ln 1,000 ≈ 145.
A composite verdict is always certain: the calculator either shows a factor or a Miller–Rabin witness, a base that a prime could never fail. A prime verdict is a proof for every number below and for Mersenne numbers , which get the Lucas–Lehmer test.
Above that bound, a number that passes is reported as a probable prime. The Baillie–PSW combination used here has been checked against every number below and has no known counterexample, but it has not been proven correct in general.
In list mode every prime is exact, because a sieve only removes numbers that have a factor. Position is where the prime falls in the sequence 2, 3, 5, 7, … (709 is the 127th prime). A twin prime has another prime 2 away, and a Mersenne prime is one less than a power of 2.
There are 25 prime numbers from 1 to 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 and 97. 2 is the only even prime, and 97 is the largest prime below 100.
Eight pairs of them are twin primes, two apart: (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43), (59, 61) and (71, 73). Three are Mersenne primes: 3, 7 and 31.
| Range | Prime numbers | Count |
|---|---|---|
| 1 to 10 | 2, 3, 5, 7 | 4 |
| 11 to 20 | 11, 13, 17, 19 | 4 |
| 21 to 30 | 23, 29 | 2 |
| 31 to 40 | 31, 37 | 2 |
| 41 to 50 | 41, 43, 47 | 3 |
| 51 to 60 | 53, 59 | 2 |
| 61 to 70 | 61, 67 | 2 |
| 71 to 80 | 71, 73, 79 | 3 |
| 81 to 90 | 83, 89 | 2 |
| 91 to 100 | 97 | 1 |
There are 143 primes from 101 to 1,000, so 168 prime numbers are below 1,000. Each block of 100 holds fewer primes than the first: 21 from 101 to 200, but only 14 from 901 to 1,000.
For any other stretch, such as the primes to 200, from 300 to 400, or the 1,229 primes up to 10,000, choose List primes in a range above and download the table as CSV.
| Range | Prime numbers | Count |
|---|---|---|
| 101 to 200 | 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199 | 21 |
| 201 to 300 | 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293 | 16 |
| 301 to 400 | 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397 | 16 |
| 401 to 500 | 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499 | 17 |
| 501 to 600 | 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599 | 14 |
| 601 to 700 | 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691 | 16 |
| 701 to 800 | 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797 | 14 |
| 801 to 900 | 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887 | 15 |
| 901 to 1,000 | 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 | 14 |
Divide the number by each prime up to its square root. If none of them divides it exactly, it is prime; the first one that does is its smallest prime factor, and the prime factorization calculator finds the rest. Checking beyond √n is never needed, because a factor larger than √n pairs with one smaller than √n.
Rule out the easy cases first. An even number above 2 is divisible by 2, a number whose digits add up to a multiple of 3 is divisible by 3, and one ending in 0 or 5 is divisible by 5. After that, every prime above 3 is one more or one less than a multiple of 6 (the form 6k ± 1), so you only need to try 5, 7, 11, 13, 17, 19 and so on. Every prime above 5 ends in 1, 3, 7 or 9.
For example, 91 looks prime, but √91 ≈ 9.5 and 91 ÷ 7 = 13, so 91 = 7 × 13 is composite. 97 is prime: the primes up to √97 ≈ 9.8 are 2, 3, 5 and 7, and each leaves a remainder.
By hand this works well up to a few thousand. For a 20-digit number it could take hundreds of millions of divisions, so computers switch to the Miller–Rabin test. This calculator does so above about 1,000,000.
In code, the same method is a short loop: if n < 2 it is not prime; if n < 4 it is prime; if n % 2 == 0 or n % 3 == 0 it is composite. Otherwise try i = 5, 11, 17, … while i * i <= n, and return composite if n % i == 0 or n % (i + 2) == 0. That loop works in Python, JavaScript, Java or C++ and is fast up to about 10¹². Miller–Rabin replaces it for bigger numbers and needs only fast powers mod n, which the modulo calculator shows step by step.
To make a list of primes rather than test one number, use the sieve of Eratosthenes. Write out the numbers from 2 to your limit. Circle 2 and cross out every later multiple of 2. Circle the next number still standing (3) and cross out its multiples, then do the same for 5 and 7. Once the next number to circle is larger than the square root of the limit, every number left is prime.
For 1 to 100 only the multiples of 2, 3, 5 and 7 need crossing out, since √100 = 10. The list mode above runs the same sieve on just the range you ask for (a segmented sieve), so it can list the primes near 10¹² without sieving everything below them.
There are infinitely many. Euclid’s proof: multiply any finite list of primes together and add 1. The result leaves a remainder of 1 when divided by each prime on the list, so its own prime factors are primes the list missed.
Primes thin out slowly as numbers grow. The prime number theorem says the count up to n is close to n / ln n, so roughly 1 in every ln n numbers near n is prime: about 1 in 7 near 1,000 and about 1 in 14 near 1,000,000.
| n | Primes up to n, π(n) | Estimate n / ln n |
|---|---|---|
| 10 | 4 | 4.3 |
| 100 | 25 | 21.7 |
| 1,000 | 168 | 144.8 |
| 10,000 | 1,229 | 1,085.7 |
| 100,000 | 9,592 | 8,685.9 |
| 1,000,000 | 78,498 | 72,382.4 |
A prime needs exactly two positive divisors. 1 has only one (itself), and 0 has infinitely many, because every number divides 0. Excluding 1 is also what keeps factorizations unique: otherwise 6 = 2 × 3 = 1 × 2 × 3 = 1 × 1 × 2 × 3, and so on.
Primes are defined as positive. In more advanced algebra, −7 is called a prime element because it is a unit (−1) times the prime 7, but it is not a prime number. The calculator reports such inputs as not prime and analyzes their absolute value.
Decide whether 221 is prime by trial division.
Answer: 221 is composite: 221 = 13 × 17. Its smallest prime factor is 13, and the nearest primes are 211 and 223.
There are 25: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89 and 97. There are 168 primes below 1,000 and 1,229 below 10,000.
No. A prime has exactly two positive divisors, and 1 has only one. Mathematicians agreed to exclude 1 so that every number has a unique prime factorization.
Yes. 2 is the smallest prime and the only even prime, since every larger even number is divisible by 2.
Yes. 7 is divisible only by 1 and 7, and it is the 4th prime, after 2, 3 and 5.
39 = 3 × 13. Its digits add up to 12, a multiple of 3, which is the quick sign that 3 divides it.
709. The 100th prime is 541 and the 1,000th is 7,919. The checker shows the position of any prime up to 1,000,000, and the list mode numbers every prime in ranges ending at or below 10,000,000.
For a small number, divide it by the primes up to its square root; for 97 that is only 2, 3, 5 and 7. For large numbers, the Miller–Rabin test is much faster than looking for factors, and this calculator answers instantly for numbers up to 200 digits.
The Miller–Rabin test checks a property that every prime has. If a number fails it for some base, that base is a witness and the number cannot be prime, even though no factor is known.
A number that passes tests every prime passes, but without a formal proof. Here that only happens above , with the Baillie–PSW test, which no composite number is known to pass.
561 = 3 × 11 × 17 is a Carmichael number: for every base a coprime to 561. The Miller–Rabin test is stronger and catches it with base 2.
Up to 200 digits. The answer is usually instant; numbers near the limit take a fraction of a second because the calculator also searches for the next and previous primes. Lists cover up to 10,000 numbers at a time, ending at 10¹² or below.
Prime factors with division steps, a factor tree, the divisor count and every divisor.
LCM and GCF of up to 10 numbers with steps: multiples, prime factors, Euclid’s algorithm and a coprime check.
a mod n with steps, negative numbers, power mod and modular inverses.
Exact n! with steps and every digit, plus digit count, trailing zeros, n!! and Stirling’s approximation.
Binary addition, subtraction and bitwise operations with steps, at 8 to 64 bits, signed or unsigned.
Type or tap expressions with exact fractions, memory, variables, constants and complex mode.
Results are calculated in your browser with methods checked by automated tests, and are intended for learning and general use. For engineering, medical, financial, legal or safety-critical decisions, verify important values independently and follow the rounding rules your work requires. How accurate are these results?