Overview
Shor showed that a quantum computer can factor an -bit integer, and compute discrete logarithms, with a number of gates polynomial in . The best known classical algorithms for both problems take time super-polynomial in , and the security of RSA, Diffie–Hellman and elliptic-curve cryptography rests on that gap. No proof that classical factoring is hard exists, so the speed-up is relative to the best known classical algorithms rather than proved.
The algorithm has a classical and a quantum part. Classically, factoring reduces to finding the order of a random number modulo . Quantumly, the order is the period of the function , and phase estimation of the modular multiplication operator, followed by the continued-fraction algorithm, finds it. Almost all of the cost is in the reversible modular arithmetic.
Intuition
The function repeats with period , the order of . A quantum computer can evaluate it on a superposition of all at once; the resulting state is periodic with period , and the quantum Fourier transform turns that period into peaks at multiples of . One measurement gives a random multiple of to high precision, and continued fractions recover the denominator.
Why does the order help? If is even, is a square root of 1 modulo . The only square roots of 1 modulo a prime are , but modulo a product of two primes there are four, and a square root makes divide without dividing either factor, so is a proper factor.
Prerequisites
Quantum phase estimation, the quantum Fourier transform, modular arithmetic and the Chinese remainder theorem.
Theorems
Under the assumptions,
Whenever this event occurs, is a square root of 1 modulo other than , and both and are nontrivial factors of .
The remaining cases are classical: if is even, 2 is a factor; if with , this is detected by computing integer -th roots for ; and if a random has , that gcd is a factor. So any procedure that returns the order of a given yields a randomized polynomial-time factoring algorithm with expected calls. This reduction, standard in number theory and used by Shor, is Theorem 5.3 of Nielsen and Chuang. The book prints the bound with exponent ; the exponent is what the argument gives and is the version in the book's errata list. It is tight: for exactly half of succeeds.
- is odd with distinct prime factors.
- is drawn uniformly from the multiplicative group of residues coprime to ; is its order, the least with .
Proof · Proof that factoring reduces to order finding
Two standard facts from elementary number theory are used (Appendix 4 of Nielsen and Chuang): the Chinese remainder theorem, by which is a group isomorphism ; and the fact that for an odd prime the group is cyclic, of order .
The gcd step. Suppose is even and . Also , since and is the least exponent with . Then while and . So shares a factor with but is not contained in it: , and likewise for .
Failure forces equal valuations. Let be the order of modulo , so that , and let be the exponent of the largest power of 2 dividing ; let be that of , so . The procedure fails when is odd or .
- If is odd, every is odd and .
- If is even and , then modulo each (as is odd), so . Since , this means contains the full power , i.e. for every .
In both cases all are equal.
Each valuation is spread out. By the Chinese remainder theorem, uniform on means that the components are independent and uniform on , and depends only on . Fix , let be a generator of the cyclic group of order , and let be the largest power of 2 dividing ; because is even. The element has order , whose 2-adic exponent is when is odd and less than when is even. As ranges uniformly over exactly half the values are odd, so and consequently for every value .
Conclusion. Conditioning on and using independence,
For this is at most . The structure of the argument follows the proof of Theorem 5.3 in Nielsen and Chuang; counting the conditioning on explicitly gives the exponent .
Write for its continued fraction, , and for its convergents. If
then , written in lowest terms, equals for some . (With in place of the statement can fail in the trivial case , : then is a convergent only of the expansion , not of . In order finding the inequality is strict.)
For a rational with the expansion has terms and all convergents can be computed with bit operations (Euclid's algorithm). In order finding, is the phase-estimation output with bits, and the theorem recovers from it. It is used in Section 5.3.1 of Nielsen and Chuang (continued fractions are treated in their Appendix 4.4); it is a classical result of number theory used for this purpose by Shor.
- is a real number, and are integers.
There is a bounded-error quantum algorithm that, on input , outputs the unique with using a number of gates polynomial in (dominated, as in factoring, by modular exponentiation).
The function on satisfies exactly when is a multiple of : it hides the subgroup generated by . Evaluating in superposition, applying Fourier transforms to both registers and measuring yields pairs satisfying a linear relation with , from which is computed classically. This is due to Shor; Kitaev placed it, with factoring, in the abelian stabilizer (hidden subgroup) framework. The same approach works for any finite abelian group with efficiently computable, uniquely represented elements; for elliptic-curve groups over prime fields the circuits were worked out by Proos and Zalka and costed in detail by Roetteler, Naehrig, Svore and Lauter.
- is a prime of bits, generates , and .
- Fault-free quantum circuits; the running time is the number of elementary gates plus classical post-processing.
Worked Examples
Factoring 15
The group has eight elements. Their orders and the outcome of the reduction:
| 1 | 2 | 4 | 7 | 8 | 11 | 13 | 14 | |
|---|---|---|---|---|---|---|---|---|
| order | 1 | 4 | 2 | 4 | 4 | 2 | 4 | 2 |
| – | 4 | 4 | 4 | 4 | 11 | 4 | 14 | |
| factors found | no | 3, 5 | 3, 5 | 3, 5 | 3, 5 | 5, 3 | 3, 5 | no |
For : , and . For : , and . The two failures are (odd order) and . Six of eight choices succeed, consistent with the bound for prime factors.
The quantum step for : the phases are with , all exactly representable once , so phase estimation returns exactly, each with probability . The outcomes and give denominator 4 and succeed; gives denominator 2, and the test rejects it; gives nothing. Half of the runs return directly.
Sizing a cryptographic instance
For of bits, the textbook order-finding circuit with uses control qubits and work qubits before arithmetic ancillas, and performs controlled modular multiplications of 2048-bit numbers. With schoolbook arithmetic each multiplication is of order gates, so the total is of order gates. The resource estimates below replace each of these choices with much cheaper ones.
Algorithms and Implementations
The unitary. On an -qubit register let for and for . It permutes basis states (because is invertible modulo ), so it is unitary, and costs no more than .
Its eigenvectors. For let
Since and , re-indexing the sum gives . Summing over , the phases cancel except at : . So the easily prepared state is a uniform superposition of eigenvectors whose phases are .
Procedure.
- Run phase estimation on with target and control qubits; read the result as .
- Compute the continued-fraction convergents of ; for each denominator in increasing order, test whether , and output the first such .
Correctness. By the superposition remark in the phase estimation record, step 1 behaves as phase estimation on for an uniform in . By the accuracy theorem with , with probability at least , , using (for the distance modulo 1 coincides with the ordinary distance, as is at least away from 0 and 1; is a failed run). The convergent theorem then puts in lowest terms, , among the convergents of . If then and step 2 returns ; otherwise is a proper divisor of and the test fails for it. The probability that a uniform is coprime to is , so repetitions suffice; combining the denominators of two runs by their least common multiple reduces this to a constant expected number of runs (section 5.3.1 of Nielsen and Chuang).
Cost. The quantum part is dominated by the controlled modular multiplications. With schoolbook arithmetic each costs gates, giving gates per run; with fast multiplication Shor obtains . The inverse QFT on qubits costs gates, or approximately. The classical continued-fraction step costs bit operations.
The algorithm is Shor's; the eigenvector formulation as phase estimation is due to Kitaev and Cleve, Ekert, Macchiavello and Mosca.
- with bits, and of unknown order .
- A reversible circuit for controlled modular multiplication by for each (the classical computer precomputes these constants).
Qubit-lean circuits. Beauregard (2003) gave a general circuit with qubits, elementary gates and depth .
Regev's variant. Regev (J. ACM 2025; preprint 2023) runs a multidimensional analogue of period finding: independent runs of a circuit with gates each, followed by classical lattice post-processing. Its correctness rests on a number-theoretic heuristic assumption, and the paper notes that its practical benefit is unclear.
Applications
Breaking RSA (factoring) and finite-field and elliptic-curve Diffie–Hellman and DSA (discrete logarithms). The prospect drives the migration to post-quantum cryptography, and the timeline debate uses the resource estimates below. The algorithm is also the prototype of the abelian hidden subgroup framework (Kitaev); see quantum algorithms.
Computational Complexity
Per run, with :
| Component | Gates | Source |
|---|---|---|
| Controlled modular exponentiation, schoolbook arithmetic | Shor | |
| Same with fast multiplication | Shor | |
| Inverse QFT on qubits | , or approximately | QFT topic |
| Classical continued fractions | bit operations | Nielsen and Chuang |
The best known classical factoring algorithms run in time that is sub-exponential but super-polynomial in ; no polynomial-time classical algorithm is known, and none has been ruled out.
Limitations and Common Pitfalls
- The QFT is cheap; arithmetic is expensive. Optimising the Fourier transform changes little; resource estimates are dominated by modular multiplication.
- Logical is not physical. Qubit counts such as are logical qubits on an error-free machine. Error correction multiplies them by a large factor; compare estimates only when they state the same error model.
- "Compiled" demonstrations. Small experiments, starting with factoring 15 in NMR by Vandersypen et al. (2001), use circuits simplified with knowledge of the answer. Smolin, Smith and Vargo (2013) showed that with such simplifications any product of two distinct odd primes can be "factored" with a two-qubit circuit, so the size of the number factored is not a meaningful benchmark; the length of the period found is.
- Not every works, not every run works. Failed runs (odd order, , , phase estimation errors) are normal and are handled by classical checks and repetition.
- Factoring is not known to be NP-hard, and Shor's algorithm gives no evidence that quantum computers solve NP-complete problems efficiently.
State of the Art
Resource estimates for the 2048-bit RSA instance, as of 2026-11 (all on a square grid of qubits with nearest-neighbour connections, a uniform physical gate error rate of 0.1 %, a surface-code cycle time of 1 µs and a control-system reaction time of 10 µs):
| Year | Physical qubits | Runtime | Main techniques | Source |
|---|---|---|---|---|
| 2019 (journal 2021) | 20 million | 8 hours | optimised modular arithmetic, surface code, magic-state distillation factories | Gidney and Ekerå |
| 2025 (preprint) | fewer than 1 million | less than a week | approximate residue arithmetic, yoked surface codes for idle qubits, magic-state cultivation | Gidney |
For elliptic curves over -bit prime fields, Roetteler, Naehrig, Svore and Lauter (2017) bounded the logical cost by qubits and Toffoli gates; for the 256-bit curve P-256 the qubit bound is 2330 logical qubits, fewer than for RSA at comparable classical security. Earlier, Proos and Zalka (2003) had estimated about 1000 qubits for a 160-bit curve against about 2000 for a 1024-bit RSA modulus.
Related Research
Quantum phase estimation, the quantum Fourier transform, fault-tolerant quantum computing for the overheads behind the resource estimates, and the overview of quantum algorithms. The lesson Resource estimation works through how such estimates are assembled.