Prime Factorization Calculator
Free prime factorization calculator: factor any integer up to one billion into primes, with the unique factorization, prime count, sum of factors, and proof.
Prime Factorization Calculator
Background.
The Quanta prime factorization calculator takes any integer n between 2 and one billion and decomposes it into the unique product of prime numbers guaranteed by the Fundamental Theorem of Arithmetic. Enter 60 and it returns 2²·3·5. Enter 13,195 and it returns 5·7·13·29. Enter 1,000,000,007 — a popular cryptographic modulus — and it tells you that the number is itself prime, so its factorization is just 1,000,000,007. Alongside the factor list the calculator returns five derived quantities mathematicians and competitive programmers ask for most often: the total prime count counted with multiplicity (the big-omega function Ω(n) from analytic number theory), the largest prime factor, the smallest prime factor, a primality flag (1 if n is prime, 0 otherwise), and the sum of the prime factors with multiplicity (sopfr(n), sometimes called the integer logarithm). The factorization is unique — that uniqueness is the content of the Fundamental Theorem of Arithmetic, proved in essentially the form we use today by Euclid in Book VII of the Elements around 300 BCE and rigorously formalised by Gauss in Article 16 of the Disquisitiones Arithmeticae in 1801 — so however you order the factors and however you arrived at them, the answer the calculator gives is the only correct answer.
Under the hood the calculator runs deterministic trial division optimised for the input range. It strips out all factors of 2 first, then iterates over odd candidates d = 3, 5, 7, 9, … dividing n by d as many times as d divides cleanly and exiting as soon as d² exceeds the remaining quotient. The early-exit condition is the entire reason the algorithm is fast: if no prime factor up to √n has been found, then whatever is left of n must itself be prime, because every composite number has a prime factor no larger than its square root. For n ≤ 10⁹ that means at most about 31,623 trial divisions — a few microseconds in JavaScript — so every input in our range factors essentially instantly.
Beyond 10⁹ the picture changes dramatically. Trial division is O(√n), which means doubling the number of digits squares the work, and by the time n has 25 digits trial division is hopeless on any single machine. That is the entire reason public-key cryptography exists. The RSA cryptosystem, published by Rivest, Shamir, and Adleman in Communications of the ACM in 1978 and still the workhorse of TLS, SSH, and PGP, derives its security from exactly this asymmetry: it is computationally trivial to multiply two 1024-bit primes p and q together to form the public modulus n = pq, but factoring that n back into p and q is so hard that the current public record — RSA-250, a 250-digit (829-bit) modulus — was only achieved in 2020 after the equivalent of roughly 2,700 CPU-years using the general number field sieve, the asymptotically fastest known classical factoring algorithm. The 2048-bit moduli used in production HTTPS today are estimated to require many billions of times that work to factor on classical hardware. (Shor's algorithm reduces this to polynomial time on a fault-tolerant quantum computer, which is why NIST has been standardising post-quantum cryptography — ML-KEM and ML-DSA — since 2024.)
Prime factorization is also where you meet the Mersenne primes — primes of the form 2ᵖ − 1, where p must itself be prime — the family that has held the world record for largest known prime since Euclid noticed their connection to perfect numbers. As of 2024 the largest known prime is M₈₆,₀₂₁,₉₆₉ = 2⁸⁶⁸²¹⁹⁶⁹ − 1, a 41-million-digit number discovered by Luke Durant under the Great Internet Mersenne Prime Search.
This page covers all of that: how the algorithm works, why it is fast on small inputs and impossible on cryptographic ones, what the Fundamental Theorem of Arithmetic actually says, where prime factorization shows up outside maths class (RSA, hash table sizing, music theory's just intonation, integer-programming relaxations), and worked examples ranging from 60 to 13,195 to a primality verdict on a billion-scale candidate. Whether you arrived for homework, contest prep, a cryptography refresher, or just to see whether a particular integer is prime, the calculator above and the explainer below cover every variant of the question.
What is prime factorization calculator?
Prime factorization is the process of writing a positive integer n ≥ 2 as a product of prime numbers. A prime number is an integer greater than 1 whose only positive divisors are 1 and itself; the first few primes are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, … . Every integer n ≥ 2 either is itself prime, in which case its prime factorization is the trivial product n = n, or it is composite and can be written as a product of two or more primes (with repetition allowed). The Fundamental Theorem of Arithmetic states that this factorization is unique up to the order of the factors: there is exactly one multiset of primes that multiplies to give n. In the standard "canonical" form we collect equal primes into prime powers and list them in increasing order: 60 = 2²·3·5, 1,000 = 2³·5³, 720 = 2⁴·3²·5. The theorem has two ingredients: existence (every n ≥ 2 has *some* prime factorization, proved by strong induction — either n is prime and we are done, or n = ab with 1 < a, b < n, and by hypothesis a and b have factorizations whose concatenation is a factorization of n) and uniqueness (no number has two genuinely different factorizations, proved using Euclid's lemma: if a prime p divides a product ab then p divides a or p divides b). Euclid proved the existence half in Proposition 31 of Book VII of the Elements (c. 300 BCE) and proved Euclid's lemma in Proposition 30; the full uniqueness statement was first stated cleanly by Gauss in Article 16 of the Disquisitiones Arithmeticae in 1801. From the canonical factorization n = p₁^a₁ · p₂^a₂ · … · pₖ^aₖ every multiplicative number-theoretic function of n can be read off mechanically: the number of divisors d(n) = (a₁+1)(a₂+1)…(aₖ+1); the sum of divisors σ(n) = ∏i (pᵢ^(aᵢ+1) − 1)/(pᵢ − 1); Euler's totient φ(n) = n·∏i (1 − 1/pᵢ); the big-omega Ω(n) = a₁ + a₂ + … + aₖ (counted with multiplicity); the little-omega ω(n) = k (distinct primes only); the sum-of-prime-factors sopfr(n) = a₁·p₁ + … + aₖ·pₖ. The same factorization is the entry point to every gcd/lcm question (gcd takes the minimum exponent of each prime, lcm takes the maximum), to modular arithmetic, to Chinese-remainder reconstruction, and to public-key cryptography.
How to use this calculator.
- Enter your integer n in the input field. Any whole number from 2 up to 1,000,000,000 is allowed — the upper bound is set by what trial division can do interactively in the browser. Decimals, negatives, zero, and one are rejected; the prime factorization of 1 is the empty product and is conventionally not asked, and primes are only defined for integers ≥ 2.
- Read the primary result — the total number of prime factors of n counted with multiplicity — at the top of the results panel. This is the big-omega function Ω(n) from analytic number theory; for n = 60 it is 4 because 60 = 2·2·3·5 has four prime factors counted with multiplicity.
- Read the full canonical factorization in the breakdown text below the primary value: it lists the primes in increasing order with their exponents, e.g. 60 = 2² · 3 · 5. If the "is prime?" output reads 1, the factorization is just n itself (n has no non-trivial factors).
- Use the smallest prime factor to spot easy divisibilities at a glance: if it is 2 the number is even; if it is 3 the digit sum of n is divisible by 3; if it is 5 the number ends in 0 or 5. The largest prime factor is the answer to Project Euler problem 3 and is the harder quantity — it can be as small as 2 (for powers of two) or as large as n itself (when n is prime).
- If you need the count of distinct primes rather than the count with multiplicity, look at the breakdown for the little-omega ω(n) value. The two functions agree exactly when n is squarefree (no prime appears with exponent ≥ 2) and diverge otherwise; 12 = 2²·3 has Ω = 3 but ω = 2.
- For inputs larger than 10⁹ the calculator will refuse the value — trial division becomes too slow to run inline. For those cases use a dedicated computer-algebra system (SageMath, PARI/GP, Mathematica) which implements Pollard rho and the elliptic-curve method for medium-sized inputs and the general number field sieve for cryptographic-scale numbers.
The formula.
The calculator implements deterministic trial division with the standard optimisations. Given n ≥ 2 it does the following. First, while n is divisible by 2, divide out a factor of 2 and append 2 to the factor list. This terminates after at most ⌊log₂ n⌋ iterations (at most 30 for n ≤ 10⁹). After this loop the remaining n is odd. Second, iterate a candidate divisor d over odd numbers starting at 3: 3, 5, 7, 9, 11, 13, … . While d² ≤ n, do the following: while d divides n exactly, divide n by d and append d to the factor list; then increment d by 2 and continue. Note that the candidate d is not required to be prime — by the time the loop reaches d = 9 every factor of 9 (namely 3) has already been divided out, so 9 will never divide what is left of n, and the loop wastes only a single comparison. Skipping the multiples of 3 with a so-called 'wheel-2-3' (advancing d through 5, 7, 11, 13, 17, 19, 23, 25, …) would shave roughly a third off the iteration count but is not worth the implementation complexity at this scale. The termination condition d² > n is the heart of the optimisation: every composite integer m has a prime factor p ≤ √m, because if both factors of m = ab satisfied a, b > √m we would have ab > m, a contradiction. Therefore if no divisor up to √n has been found, whatever value of n remains must itself be prime, and the loop exits with that residual value appended to the factor list. Third, if after the loop the residual n is > 1, append it to the factor list as the final (and necessarily largest) prime factor. The full factor list is then in non-decreasing order by construction, and the canonical 'prime powers' form is obtained by run-length-encoding it. From the factor list the five reported outputs follow directly: primeCount = length of the factor list = Ω(n); largestPrime = last element; smallestPrime = first element; isPrime = 1 if length == 1 else 0; sumOfFactors = sum of the factor list = sopfr(n). The worst-case running time is O(√n) divisions, achieved when n is prime (every odd candidate up to √n is tried in vain). For n = 10⁹ that worst case is about 15,811 division operations — milliseconds in JavaScript, instant from the user's perspective. Beyond about 10¹² the O(√n) cost becomes painful interactively and serious factoring requires sub-exponential algorithms: Pollard rho for medium n (heuristic O(n¹ᐟ⁴)), the elliptic-curve method (running time governed by the size of the smallest prime factor of n, not n itself), and the general number field sieve (sub-exponential, currently best-known for cryptographic-scale moduli).
A worked example.
Take n = 60. Trial division starts at d = 2: 60 / 2 = 30 (append 2), 30 / 2 = 15 (append 2). Now 15 is odd, so the 2-loop exits. Move to d = 3: 15 / 3 = 5 (append 3). 5 is not divisible by 3. Increment to d = 5. Now check the termination condition: d² = 25 > 5, so the loop exits early. The residual 5 is > 1, so append it to the factor list as the final prime. The factor list is [2, 2, 3, 5], which run-length-encodes to 60 = 2² · 3 · 5. From the factor list the calculator derives every reported output: Ω(60) = 4 (four primes counted with multiplicity), smallestPrime = 2, largestPrime = 5, isPrime = 0 (because Ω > 1), and sopfr(60) = 2 + 2 + 3 + 5 = 12. The distinct-prime count ω(60) reported in the breakdown is 3 (the three distinct primes 2, 3, 5). As a sanity check on the Fundamental Theorem of Arithmetic, every other way of factoring 60 collapses to the same multiset: 60 = 6 · 10 = (2 · 3)(2 · 5) = 2² · 3 · 5, or 60 = 4 · 15 = 2² · 3 · 5, or 60 = 12 · 5 = 2² · 3 · 5 — the order of discovery changes but the multiset {2, 2, 3, 5} is invariant. Contrast this with n = 1,000,000,007. Trial division grinds through every odd d from 3 up to ⌊√1,000,000,007⌋ = 31,622 without finding a divisor, exits the loop, and reports the residual 1,000,000,007 as a prime in its own right. That number is in fact prime — it is the modulus used in tens of thousands of competitive-programming problems precisely because it is prime, large enough that no modular collision is plausible, and small enough that products fit in a 64-bit integer.
Frequently asked questions.
What is prime factorization and why is it unique?
What algorithm does this calculator use?
Why does the calculator cap inputs at one billion?
How is prime factorization used in cryptography?
What is a Mersenne prime?
What is the difference between Ω(n) and ω(n)?
How can I tell if a number is prime quickly?
What happens to performance for numbers larger than 10⁹?
Why is prime factorization important beyond cryptography?
Is there a closed-form formula for the n-th prime?
References& sources.
- [1]Euclid. Elements, Book VII, Propositions 30–32 (c. 300 BCE). Proposition 30 is Euclid's lemma (if a prime divides a product, it divides one of the factors); Proposition 31 establishes existence of a prime factorization; Proposition 32 packages the result. English translation and commentary in Heath, T. L. The Thirteen Books of Euclid's Elements, Cambridge University Press, 1908; reprinted by Dover, 1956.
- [2]Hardy, G. H. and Wright, E. M. An Introduction to the Theory of Numbers, 6th edition, revised by Heath-Brown and Silverman. Oxford University Press, 2008. Chapters I–II contain the canonical exposition of the Fundamental Theorem of Arithmetic, prime-counting estimates, and the elementary theory of Ω, ω, σ, and φ.
- [3]Knuth, Donald E. The Art of Computer Programming, Volume 2: Seminumerical Algorithms, 3rd edition. Addison-Wesley, 1997. §4.5.4 ('Factoring into Primes') is the definitive computer-science treatment of trial division, Pollard rho, the elliptic-curve method, the quadratic sieve, and the general number field sieve.
- [4]NIST Digital Library of Mathematical Functions, Chapter 27 ('Functions of Number Theory'), by T. M. Apostol. Authoritative reference definitions of the prime-counting function π(x), Ω(n), ω(n), Euler's totient, Möbius function, and Mertens' theorems. Online edition continuously updated by NIST.
- [5]Rivest, R. L., Shamir, A., and Adleman, L. 'A Method for Obtaining Digital Signatures and Public-Key Cryptosystems.' Communications of the ACM 21(2): 120–126, February 1978. The original peer-reviewed RSA paper — the canonical citation for the link between integer factorization hardness and public-key cryptography.
- [6]Boudot, F., Gaudry, P., Guillevic, A., Heninger, N., Thomé, E., and Zimmermann, P. 'Comparing the Difficulty of Factorization and Discrete Logarithm: A 240-digit Experiment.' CRYPTO 2020, Lecture Notes in Computer Science vol. 12171, Springer. Documents the RSA-240 / RSA-250 factoring records and the state of the art of the general number field sieve as of 2020.
- [7]Caldwell, C. K. and Honaker, G. L., eds. The Prime Pages — PrimePages.org / primes.utm.edu. Authoritative database of large primes, Mersenne primes, and the Great Internet Mersenne Prime Search (GIMPS) records, including M_82,589,933 (December 2024).
In this category
Embed
Quanta Pro
Paid features are coming later.
- All 313 calculators remain free
- No billing is enabled