🔢 Math & Numbers Free Forever

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.

Whole Number
About This Tool

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

Step 1 Strip out all factors of 2 first 2 is handled as a special case before the main loop, dividing it out repeatedly until the number is odd. This immediately halves the search space for every other step, since no even number past this point needs checking.
Step 2 Test only odd candidates Starting from 3, the tool tries only odd numbers as potential factors, skipping every even candidate since they were already eliminated in step 1.
Step 3 Stop at the square root of what remains The loop only needs to test candidates up to the square root of the remaining value, not the original number. If no factor exists at or below that square root, whatever remains must itself be prime, since any composite number has at least one factor at or below its own square root.
Step 4 Recompute the limit as the remainder shrinks Each time a factor is found and divided out, the square root limit is recalculated against the smaller remaining value, so the search window keeps shrinking as the algorithm progresses rather than staying fixed to the original number.
// trial division: strip 2s, then test odd candidates up to sqrt take(2); for (var p = 3; p * p <= rem; p += 2) take(p); if (rem > 1) factors.push({ p: rem, e: 1 });

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.

NumberFactorizationDistinct primes
3602³ × 3² × 53
9797 (prime)1
10242¹&sup0;1
10017 × 11 × 133
Worked example: 360. Dividing out 2s three times leaves 45 (360 ÷ 8). 45 is odd, so the odd-candidate loop begins at 3, which divides in twice, leaving 5 (45 ÷ 9). At that point the square root of 5 is under 3, so the loop stops, and the remaining value, 5, is added directly as a prime factor. Final result: 360 = 2³ × 3² × 5. Multiply it back out yourself: 8 × 9 × 5 = 360, confirming the factorization is exact, not approximate.
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.

Trial division up to sqrt(n) Exact BigInt arithmetic Supported up to 10^12

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.

Common Questions

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.