Prime Factorization Tool: Break Down Any Number
Enter any whole number up to one trillion and see its prime factorization, every divisor, the divisor count and sum, and the nearest primes.
How this tool breaks a number down into its prime factors using trial division
Every whole number greater than 1 can be built from prime numbers multiplied together in exactly one way, ignoring order. That statement is the Fundamental Theorem of Arithmetic, and it is why prime factorization is not just a puzzle, it is a unique fingerprint for every integer. This tool finds that fingerprint using trial division, the most direct method there is: testing whether small primes divide evenly into the number, and dividing them out when they do.
The whole process runs client side with exact integer arithmetic, and it is capped at numbers up to 10 to the power 12, one trillion, which keeps even the worst case, a large prime near that ceiling, resolving in well under a second in the browser.
The trial division algorithm
Every number up to one trillion fits exactly in a JavaScript number, which is exact for whole numbers up to about 9 quadrillion. So instead of taking a square root, the loop simply checks p × p against what remains. That comparison is exact, with no floating point rounding creeping into a decision about whether a candidate factor is above or below the limit.
| Number | Factorization | Distinct primes |
|---|---|---|
| 360 | 2³ × 3² × 5 | 3 |
| 97 | 97 (prime) | 1 |
| 1024 | 2¹&sup0; | 1 |
| 1001 | 7 × 11 × 13 | 3 |
Special cases handled explicitly
0 has no factorization since every number would divide it, and 1 is neither prime nor composite, it is the empty product. Both are called out directly rather than left to produce a confusing blank result.
Exponent notation
Repeated factors are shown with superscript exponents, like 2³, and the result also reports the total factor count both by distinct primes and counted with multiplicity.
- Fundamental Theorem of Arithmetic is the proof that every integer has exactly one prime factorization.
- Trial division covers the algorithm this tool implements, along with its performance limits versus more advanced factoring methods.
- Integer square root explains the square root boundary that the p × p check enforces.
What factorisation is good for
Simplifying fractions and radicals in algebra homework, finding the greatest common divisor or least common multiple by comparing prime factorizations directly, checking whether a number is prime before using it in a hashing or modular arithmetic context, and teaching the building block concept behind cryptographic systems that rely on factoring being computationally hard for very large numbers, even though this tool's 10^12 ceiling is nowhere near cryptographic scale. Any time you need to see what a number is actually made of, rather than just what it equals, this is the operation for it.
Frequently Asked Questions
Prime factorization is expressing a whole number as a product of prime numbers (numbers greater than 1 with no divisors other than 1 and themselves), such as 84 = 2² × 3 × 7. Every whole number greater than 1 has exactly one such factorization, this uniqueness is known as the fundamental theorem of arithmetic.
Start by dividing the number by the smallest prime, 2, repeatedly until it no longer divides evenly, then move to the next prime, 3, and repeat, continuing through 5, 7, 11, and so on until what remains is either 1 or itself a prime number. This tool automates exactly that process, called trial division.
If a number n has a factor larger than its square root, it must also have a corresponding factor smaller than the square root (since factors pair up to multiply back to n), so if no factor is found up to the square root, the number itself must be prime. This shortcut dramatically reduces how many divisors need to be tested, especially for large numbers.
A prime number has exactly two positive divisors, 1 and itself (like 2, 3, 5, 7, 11), while a composite number has more than two divisors and can be broken down into smaller prime factors (like 4 = 2×2, or 15 = 3×5). The number 1 is neither prime nor composite, it's a special case with only one positive divisor.
Trial division's worst case, testing whether a very large number is itself prime, requires checking every potential factor up to its square root. For a number near one trillion, that's about a million checks, which completes in a fraction of a second, but larger inputs would require checking billions of potential factors, which would make the browser feel unresponsive. More advanced algorithms (like Pollard's rho) can factor larger numbers faster but add significant complexity.
Yes, once you have the prime factorization of two numbers, their greatest common divisor is the product of the shared prime factors at the lowest shared exponent, and their least common multiple is the product of all prime factors at the highest exponent appearing in either number. This is a classic alternative to the Euclidean algorithm for finding GCD and LCM.
From the blog
Number theory, lightly
Base systems, primes and the statistics people get wrong.