Every whole number greater than 1 is either a prime (divisible only by 1 and itself) or a product of primes, and that product is unique apart from the order of the factors. This is the fundamental theorem of arithmetic, and the product is called the number's prime factorization. For example .
This prime factorization calculator finds that product for any whole number up to (a thousand trillion). It shows the result in exponent form, the expanded product, the list of distinct prime factors, a step-by-step factor tree, and the arithmetic facts that follow from the factorization: the number of divisors, the sum of divisors and, for smaller results, the full list of divisors.
It also answers the simple question "is it prime?". If the number is prime, the calculator says so and explains why; if not, it gives the nearest primes below and above it. That makes the page a quick prime number checker as well as a prime factor calculator, and a companion to the GCD and LCM calculator, which uses factorizations to compare several numbers at once.
How to use this calculator
- Type a whole number between 2 and 1,000,000,000,000,000 in the box. Commas or spaces between groups of three digits are accepted.
- Read the prime factorization at the top, written with exponents, such as .
- Check Is it prime? for a yes/no answer, and the previous and next primes.
- Open the steps to follow the factor tree: at each line the smallest prime factor is split off, until the last factor is itself prime.
- Use the table of prime powers, the divisor count and the divisor sum for exercises on divisors, perfect numbers or simplifying square roots.
The formula
If with distinct primes , then every divisor of has the form with . Counting and adding them gives
How the factors are found. The calculator first divides by 2, 3 and 5, then by the numbers coprime to 30 (a "wheel" that skips multiples of 2, 3 and 5) up to . Any factor left over above is checked with the Miller–Rabin test using the first 13 primes as bases, which is proven to give no false answer below . If that cofactor is composite, Pollard's rho method splits it: it iterates and finds a factor as when the sequence repeats modulo a hidden prime. All arithmetic is done with exact integers.
Worked example
A classic: 360. Split off the smallest prime each time: , , , , , and 5 is prime. So . It has divisors, and their sum is .
A squarefree number: 1001 . Every exponent is 1, so it has divisors.
A large number: 600,851,475,143 , found in a fraction of a second. Likewise , a product of two seven-digit primes that Pollard's rho separates.
Is 97 prime? No prime up to (2, 3, 5, 7) divides it, so yes; the next prime is 101.
Factor tree or division ladder?
A factor tree writes the number at the top and splits it into any two factors, then splits each branch again until every leaf is prime. Two students can draw different trees for 360 (say or ), but the leaves always give the same primes — that is the uniqueness part of the fundamental theorem. The calculator draws the most systematic version, the division ladder: it always splits off the smallest prime, so each step reads "number = prime × what is left". Reading the primes down the left side gives the factorization.
What the factorization is used for
- Simplifying fractions and roots: . See the square root calculator.
- GCD and LCM: take the lowest or highest power of each common prime.
- Divisor questions: perfect numbers satisfy (for 28: ); a number is a perfect square exactly when every exponent is even.
- Cryptography: RSA relies on the fact that multiplying two large primes is easy while factoring the product is hard. Numbers up to are small enough to factor instantly; RSA moduli have hundreds of digits.
Frequently asked questions
How do I know if a number is prime?
Try dividing it by every prime up to its square root. If none divides it, it is prime. For 97 you only need to test 2, 3, 5 and 7. For large numbers the calculator uses the Miller–Rabin test, which is exact for every number this page accepts.
Is 1 a prime number?
No. A prime has exactly two divisors, 1 and itself, and 1 has only one. Excluding 1 is what keeps prime factorizations unique; otherwise you could multiply by 1 as many times as you like.
What is the difference between factors and prime factors?
Factors (divisors) of 12 are 1, 2, 3, 4, 6 and 12. Its prime factors are only 2 and 3, and the prime factorization 2² × 3 builds all six divisors from them.
Why do I get a different factor tree than my teacher?
A factor tree can start with any pair of factors, so trees can look different. The primes at the ends of the branches are always the same, with the same exponents.
How large a number can I factor?
Up to 10¹⁵. Every result is exact: trial division handles small factors and Pollard’s rho splits the rest, so even a product of two seven-digit primes is factored almost instantly.
Sources
- Knuth, D. E. — The Art of Computer Programming, Vol. 2, §4.5.4 Factoring into Primes
- Crandall, R. & Pomerance, C. — Prime Numbers: A Computational Perspective, 2nd ed., Springer (2005)
- Sorenson, J. & Webster, J. — Strong pseudoprimes to twelve prime bases, Math. Comp. 86 (2017)
- OEIS A000005 — number of divisors τ(n)
- OEIS A000203 — sum of divisors σ(n)
- Weisstein, Pollard rho Factorization Method — Wolfram MathWorld
Last updated: