Level 3 · Algorithms

Shor’s Algorithm

About 4,952 words · roughly 23 minute read · sources checked December 2, 2026

Shor’s algorithm is the reason governments and banks pay attention to quantum computing. Published by Peter Shor in the mid-1990s, it factors a large integer in a number of steps that grows only polynomially with its number of digits, whereas the best known classical methods take super-polynomial time. Because the security of RSA rests on the difficulty of factoring, a large enough quantum computer would break it.

This lesson explains the algorithm so that you can reproduce its arithmetic. The surprising fact is that most of the work is ordinary number theory. The quantum computer is used for exactly one job, finding the period of a function, and this lesson shows that step with real numbers for N = 15 and N = 21, including the cases where it fails and how the algorithm recovers.

We then turn to the practical questions. How many qubits and how much time would it take to factor a 2048-bit RSA number? What do the published estimates assume? How far are today’s machines from that? And what is being done in the meantime? The answers are given with sources and with care, because this topic attracts exaggeration in both directions.

What you will learn

  • How factoring reduces to finding the order of a number modulo N, with worked examples.
  • Why the reduction succeeds for most choices of a, and what to do when it fails.
  • The structure of the quantum period-finding circuit and why it produces peaks.
  • How continued fractions recover the period from a measurement.
  • A full worked distribution for N = 21, including a partial failure and the fix.
  • The gate and qubit cost formulas and the 2019 and 2025 RSA-2048 estimates, with assumptions.
  • What the algorithm does not break, and the NIST post-quantum standards.

Helpful first: Quantum Algorithms, Quantum Gates.

The problem and why it matters

The factoring problem is simple to state. Given a composite integer N, find integers p and q greater than 1 with p·q = N. For small numbers this is trivial. For a number with hundreds of digits it is believed to be very hard for classical computers. The best classical algorithms known, such as the general number field sieve, run in sub-exponential but super-polynomial time in the number of digits. No proof exists that factoring is classically hard, but decades of effort have not produced a polynomial-time method.

That belief underlies RSA, the public-key system widely used to establish secure connections and to sign data. An RSA public key contains N = p·q, the product of two large secret primes, and its security rests on the assumption that no one can recover p and q from N. Shor’s algorithm, published in the mid-1990s, showed that a quantum computer could factor N in time polynomial in log N. Montanaro’s survey states the cost as O((log N)³) quantum gates for the core algorithm, described as a super-polynomial speed-up over the best known classical algorithm.

What is and is not at stake

Shor’s algorithm threatens public-key systems based on factoring and on discrete logarithms, which includes RSA, classical Diffie–Hellman and elliptic-curve cryptography. It does not threaten symmetric ciphers such as AES in the same way, and it does not threaten the new lattice-based and hash-based schemes designed to be quantum-resistant.

Step 1: reduce factoring to order finding

Most of Shor’s algorithm is a classical reduction, discovered earlier in number theory. Choose a number a between 2 and N − 1 that shares no factor with N. The sequence a, a², a³, … taken modulo N must eventually return to 1, because there are only finitely many values and the map is reversible. The smallest r > 0 with aʳ ≡ 1 (mod N) is called the order (or period) of a modulo N.

7^x mod 1517413period42^x mod 2112481611period6One full turn (x up by r) returns to 1. Clockwise from the top.
The powers of 7 modulo 15 cycle with period 4, and the powers of 2 modulo 21 cycle with period 6.

Now suppose r is even. Then (a^(r/2))² ≡ 1 (mod N), so N divides (a^(r/2) − 1)(a^(r/2) + 1). If, in addition, a^(r/2) is not congruent to −1 modulo N, then neither factor is a multiple of N by itself, so each shares a non-trivial factor with N. The greatest common divisors gcd(a^(r/2) − 1, N) and gcd(a^(r/2) + 1, N) then give factors of N. The Euclidean algorithm computes a gcd in time polynomial in the number of digits.

Worked example

Factoring 15 with a = 7

  1. Powers of 7 modulo 15: 7¹ = 7, 7² = 49 ≡ 4, 7³ ≡ 28 ≡ 13, 7⁴ ≡ 91 ≡ 1. So the order is r = 4.
  2. r is even, and 7^(r/2) = 7² = 49 ≡ 4, which is not 14 (≡ −1 mod 15). So the method applies.
  3. gcd(7² − 1, 15) = gcd(48, 15) = 3, and gcd(7² + 1, 15) = gcd(50, 15) = 5. Indeed 15 = 3 × 5. ✓

Worked example

Factoring 21 with a = 2

  1. Powers of 2 modulo 21: 2, 4, 8, 16, 32 ≡ 11, 64 ≡ 1. The order is r = 6.
  2. 2^(r/2) = 2³ = 8, which is not 20 (≡ −1 mod 21), so the method applies.
  3. gcd(8 − 1, 21) = gcd(7, 21) = 7, and gcd(8 + 1, 21) = gcd(9, 21) = 3. Indeed 21 = 3 × 7. ✓

When the reduction fails

Two things can go wrong. The order r may be odd, in which case a^(r/2) is not an integer. Or r is even but a^(r/2) ≡ −1 (mod N), in which case one of the two gcds is 1 and the other is N, so nothing is learned. For example with N = 15 and a = 14, the order is 2, and 14¹ ≡ −1 (mod 15), so this a fails. In either case you simply choose another a.

NValues of a coprime to NValues that give factorsFraction
157686%
2111655%
35231878%
77593051%

How often a random a works, by exhaustive count for four small N.

The counts are about one half or better in every case, which fits a standard theorem: for an odd composite N that is not a prime power, a randomly chosen a yields a usable even order with probability at least one half. So a few attempts almost always suffice. Before running any of this, a classical program removes the easy cases: even N, perfect prime powers, and lucky choices of a where gcd(a, N) is already a non-trivial factor.

Step 2: finding the order with a quantum computer

Computing the order r classically means finding the period of the sequence aˣ mod N, and no efficient classical method is known for large N. The quantum computer’s task is exactly this period finding, and the structure is the same as in Simon’s problem.

Input NEasy cases? even N, prime powerPick random a, check gcd(a, N) = 1Period finding: superpose, a^x mod N, QFT, measureContinued fractions give candidate rr even and a^(r/2) ≠ −1 mod N ?gcd(a^(r/2) ± 1, N) gives the factorsif no:new a Orange box: the only quantum step.
The structure of Shor’s algorithm. Only the period-finding box is quantum. The rest is classical number theory and is cheap.
  1. Choose t counting qubits so that Q = 2ᵗ is at least N². Put them in the uniform superposition (1/√Q) Σₓ |x⟩, with a second register of about log₂N qubits holding |1⟩.
  2. Compute the function in superposition: (1/√Q) Σₓ |x⟩ |aˣ mod N⟩. This is the modular exponentiation, the expensive step.
  3. Measure the second register. It yields some value aˣ⁰ mod N. The first register collapses to an equal superposition of all x with that value, which are x₀, x₀ + r, x₀ + 2r, …, a regular comb with spacing r.
  4. Apply the quantum Fourier transform to the first register. A comb with spacing r in x-space becomes a comb with spacing Q/r in frequency space. The amplitudes concentrate on the integers y near multiples of Q/r.
  5. Measure the first register to get y. Then y/Q is close to k/r for some integer k. A classical continued-fraction computation recovers the fraction k/r, and hence r.

Why does the period show up as peaks? The QFT of a comb adds up the waves e^(2πi·xy/Q) over x = x₀, x₀ + r, … These waves are in phase, and add constructively, only if y·r/Q is close to an integer. That is exactly when y is close to a multiple of Q/r. For other y the waves point in different directions and cancel. This is the interference mechanism of the earlier lessons in action: the QFT turns a hidden spacing into a visible peak.

Worked example

Full distribution for N = 15, a = 7, with Q = 16

  1. The period is r = 4 and Q = 16 is a multiple of r, so the peaks are exactly at multiples of Q/r = 4.
  2. After measuring the second register, the first register is a comb such as (|x₀⟩ + |x₀ + 4⟩ + |x₀ + 8⟩ + |x₀ + 12⟩)/2, with x₀ one of 0, 1, 2, 3.
  3. After the QFT the probability is exactly ¼ on each of y = 0, 4, 8, 12 and 0 elsewhere. I computed the full distribution numerically and it matches.
  4. Interpret each outcome. y = 0 gives 0/16 = 0, which carries no information. y = 8 gives 8/16 = 1/2, whose denominator is 2, which fails because 7² ≡ 4, not 1. y = 4 gives 4/16 = 1/4 and y = 12 gives 12/16 = 3/4, both with denominator 4, which succeed.
  5. So one run gives r = 4 with probability ½ and otherwise the algorithm repeats. The expected number of runs is 2.

Why the Fourier transform of a comb is a comb: the algebra

The peak structure can be derived in a few lines when the period divides Q, and the derivation shows exactly where the interference happens. After measuring the second register, the first register holds an equal superposition of the M = Q/r values x₀, x₀ + r, …, x₀ + (M − 1)r.

|φ⟩ = (1/√M) Σ_{j=0}^{M−1} |x₀ + j r⟩
QFT|φ⟩ = (1/√(QM)) Σ_y [ Σ_j e^(2πi (x₀ + j r) y / Q) ] |y⟩
The first register before and after the Fourier transform.

The inner sum is a geometric series in j with ratio e^(2πi r y / Q). It equals M when r·y/Q is an integer, that is, when y is a multiple of Q/r, and it equals zero for every other y, because the M terms are equally spaced points around the unit circle and cancel. So the amplitude is zero everywhere except at the multiples of Q/r, where it has size M/√(QM) = √(M/Q) = 1/√r.

Worked example

Checking against N = 15, a = 7

  1. Here r = 4, Q = 16 and M = Q/r = 4. The amplitude at each multiple of Q/r = 4 has size 1/√r = 1/2, so its probability is ¼.
  2. There are r = 4 such multiples (y = 0, 4, 8, 12), and 4 × ¼ = 1, so no probability is left elsewhere. This agrees with the distribution computed numerically.
  3. The phase x₀ in e^(2πi x₀ y/Q) is a global phase at each peak, so the random value of x₀ that the second-register measurement selects does not change the probabilities. That is why measuring the second register is harmless: all x₀ lead to the same peak positions.

When r does not divide Q, as for r = 6 and Q = 512, the geometric series no longer cancels exactly. The sum is large when r·y/Q is within about 1/M of an integer and small otherwise, so the exact zeros become a main lobe of finite width centred on each multiple of Q/r. A standard analysis, which I have not re-derived here, shows that each y within 1/2 of a multiple of Q/r has probability at least about 4/(π²r). For r = 6 this lower bound is 0.068, consistent with the 0.114 computed for the peaks of the N = 21 example. Since there are r such peaks, at least about 4/π² ≈ 41% of the total probability sits on the good outcomes, and the actual figure for this example is higher (about 79%).

The one-sentence mechanism

Equally spaced terms add up only when their phases line up, and a comb in position space lines up exactly at a comb in frequency space whose spacing is inverse to the original. The period r appears as the spacing Q/r, which the measurement samples.

A harder case: N = 21, where the peaks are not exact

When the period r does not divide Q, as for r = 6 with Q = 512, the peaks are not sharp. This is the realistic case and shows why the continued-fraction step and the condition Q ≥ N² are needed. Take N = 21 and a = 2, whose order is r = 6. Choose Q = 2⁹ = 512, which is bigger than N² = 441.

00.167850.1141710.1142560.1673410.1144270.114measured value y (Q = 512), peaks near k·Q/6 = k·85.3probabilitySix peaks hold about 79% of the probability; the rest sits next to them.
Measurement distribution for N = 21, a = 2, Q = 512. The peaks sit near multiples of Q/r = 85.33. Heights are exact for y = 0 and 256 and about 0.114 for the other four.

The distribution has six main peaks near k·512/6 = 0, 85.3, 170.7, 256, 341.3, 426.7, for k = 0 to 5. Computing it numerically gives the following.

Peak yy/512Nearest fraction with denominator below 21ProbabilityWhat it yields
000/10.167Nothing (k = 0)
850.1661/60.114r = 6 ✓
1710.3341/30.114Candidate 3 fails (2³ = 8 ≠ 1), but 2 × 3 = 6 works
2560.51/20.167Candidate 2 fails (2² = 4 ≠ 1); its multiple 6 works
3410.6662/30.114Same as 171: denominator 3
4270.8345/60.114r = 6 ✓

The six peaks for N = 21, a = 2. Each peak also has small-probability neighbours (for example 84, 86, 170, 172), which give the same fractions.

Adding up all the outcomes whose fraction reduces to denominator exactly 6, I find the chance of reading the period directly in one run is about 31%. The six peaks together hold about 79% of the probability, and the rest is spread over nearby values. A few things are worth noting.

  • Fractions are reduced. When k and r share a factor, the fraction k/r simplifies to one with a smaller denominator, for example 3/6 = 1/2. This is why r is not always read out directly. The measured denominator is a divisor of r.
  • A divisor of r is still useful. If a candidate d fails (ad ≢ 1), try small multiples 2d, 3d, … until ad ≡ 1. For the outcome with denominator 3, the multiple 6 works: 2⁶ = 64 ≡ 1 (mod 21).
  • Combining several runs also works. If one run gives denominator 3 and another gives 2, the least common multiple is 6, the true period.
  • Failed runs are cheap to repeat. The expected number of runs is small, typically a handful.

Why continued fractions recover the period

The measured y satisfies |y/Q − k/r| ≤ 1/(2Q). Since Q ≥ N² and r < N, we have 1/(2Q) < 1/(2N²) < 1/(2r²). A classical theorem says that any fraction within 1/(2r²) of a real number is one of that number’s continued-fraction convergents. So computing the convergents of y/Q and picking the one with denominator below N finds k/r. This is why Q must be at least N²: it guarantees that the approximation is good enough to identify the fraction uniquely.

Worked example

Continued fractions for y = 85 and y = 171

  1. 85/512 has the continued-fraction expansion [0; 6, 42, 2]. Its convergents are 0/1, 1/6, 42/253 and 85/512. The only one with a denominator below N = 21 (other than the trivial 0/1) is 1/6, so r = 6.
  2. 171/512 has the expansion [0; 2, 1, 170], with convergents 0/1, 1/2, 1/3 and 171/512. The convergent below N = 21 with the smallest error is 1/3, so the candidate period is 3.
  3. Test: 2³ = 8 ≢ 1 (mod 21), so the candidate fails. Test the multiple 6: 2⁶ = 64 = 3 × 21 + 1 ≡ 1. So r = 6 anyway.
  4. From r = 6 the factors follow as before: gcd(2³ − 1, 21) = 7 and gcd(2³ + 1, 21) = 3.

Why modular exponentiation dominates the cost

The QFT on 2n qubits is cheap, with about n² gates. The step that dominates the cost of Shor’s algorithm is computing aˣ mod N in superposition. This must be done reversibly, with no information thrown away, and for an n-bit number N it involves about 2n modular multiplications, each built from additions of n-bit numbers. In the original analysis the total is a polynomial of order n³ elementary gates, the O((log N)³) figure cited by Montanaro.

The scale in a real implementation is set by the number of Toffoli gates, which implement the reversible AND inside the additions. Gidney and Ekerå give the abstract cost of their 2019 method for an n-bit modulus as roughly 3n + 0.002·n·lg n logical qubits and roughly 0.3n³ + 0.0005·n³·lg n Toffoli gates, with measurement depth of roughly 500n² + n² lg n. Here lg means the base-2 logarithm.

Worked example

Plugging in n = 2048

  1. Logical qubits: 3 × 2048 + 0.002 × 2048 × lg 2048 = 6,144 + 0.002 × 2048 × 11 ≈ 6,144 + 45 = 6,189.
  2. Toffoli gates: 0.3 × 2048³ + 0.0005 × 2048³ × 11. Since 2048³ ≈ 8.59 × 10⁹, the first term is about 2.58 × 10⁹ and the second about 4.7 × 10⁷, for a total of about 2.6 × 10⁹.
  3. So the algorithm needs roughly six thousand logical qubits and a few billion Toffoli gates for a 2048-bit modulus. These are logical, error-corrected qubits and gates.
  4. Each Toffoli, as shown in the gates lesson, needs several T-type gates (7 in the standard exact decomposition, though magic-state techniques reduce the cost), so the T-count is of order 10¹⁰.

The huge gap between ‘thousands of logical qubits’ and ‘millions of physical qubits’ is the overhead of error correction. With a physical error rate of 10⁻³, a surface-code logical qubit that survives billions of operations may need on the order of a thousand physical qubits, and extra qubits are needed for the machinery that produces the special states required for non-Clifford gates.

A back-of-envelope check on the 20 million figure

The headline qubit counts come from detailed analysis, but you can see where they come from with a rough calculation. This is an illustration with textbook rules of thumb, not a reproduction of the papers.

Worked example

How big must each logical qubit be?

  1. Take the 2019 numbers: about 6,189 logical qubits (from the formula above) running for about 8 hours with a 1 µs surface-code cycle. The number of cycles is 8 × 3,600 s / 1 µs = 2.88 × 10¹⁰.
  2. The number of logical qubit-cycles is about 6,189 × 2.88 × 10¹⁰ ≈ 1.8 × 10¹⁴. For the whole computation to succeed with decent probability, each qubit-cycle must have a logical error below about 1/(1.8 × 10¹⁴) ≈ 5.6 × 10⁻¹⁵.
  3. A common rule of thumb for the surface code is that the logical error per cycle is about 0.1 × (p/p_th)^((d+1)/2), where p is the physical error rate, p_th ≈ 1% is the threshold and d is the code distance. With p = 10⁻³ the ratio is 0.1.
  4. Requiring 0.1 × 0.1^((d+1)/2) ≤ 5.6 × 10⁻¹⁵ gives (d + 1)/2 ≥ 13.25, so (d + 1)/2 = 14 and d = 27.
  5. A distance-27 surface-code patch uses roughly 2d² ≈ 1,458 physical qubits. Multiplying by 6,189 logical qubits gives about 9 million physical qubits for the data alone.
  6. The remaining physical qubits in the estimate go to the factories that produce magic states for the Toffoli gates, and to routing space. So the 20 million figure is plausible in order of magnitude.

The calculation also shows why the estimates are sensitive to the physical error rate. The exponent (d + 1)/2 depends on log(1/p). If the physical error rate were 10⁻⁴ instead, the ratio p/p_th would be 0.01, and (d + 1)/2 ≥ 6.6 would give d around 13, a patch of about 340 physical qubits, roughly four times smaller. Better physical qubits shrink the machine directly, and part of the 2025 improvement came from storing idle logical qubits more efficiently and replacing magic-state distillation with magic state cultivation, so that error correction cost less.

Equally, the calculation shows why running time and qubit count trade off. A machine with fewer factories takes longer, and a longer run needs a smaller error per cycle, which pushes up the distance. The 2025 estimate, with fewer than a million qubits and less than a week of running, sits at a different point on the same trade-off curve.

A second worked example: N = 35, where some runs fail

The N = 21 example shows a clean run. This one shows what an unlucky measurement looks like and how the algorithm recovers, because real runs mix both.

Worked example

Factoring 35 with a = 2

  1. gcd(2, 35) = 1, so no luck from the gcd. The order of 2 modulo 35 is r = 12, since 2¹² = 4096 = 117 × 35 + 1 and no smaller power works (I checked by computer). Use t = 12 counting qubits, so Q = 2¹² = 4096, comfortably above N².
  2. The measured value y lands near a multiple of Q/r = 341.33. Suppose y = 1707. Then y/Q ≈ 0.41675, and the continued-fraction approximation with denominator below 35 is 5/12. The denominator 12 is the true period. Check: 2¹² mod 35 = 1. ✓
  3. Take half: 2⁶ = 64 ≡ 29 (mod 35), which is not ±1, so the method works. gcd(29 − 1, 35) = gcd(28, 35) = 7 and gcd(29 + 1, 35) = gcd(30, 35) = 5. So 35 = 5 × 7. ✓
  4. Now suppose instead the measurement was y = 1365. Then y/Q ≈ 0.33325, and the best fraction is 1/3, so the candidate period is 3. But 2³ = 8 ≠ 1 (mod 35), so the candidate fails the check and is discarded. This happens because the numerator s = 4 shares a factor with r = 12, so the fraction reduces to 1/3.
  5. Likewise y = 683 gives 1/6, candidate 6, and 2⁶ = 64 ≡ 29 ≠ 1: fail. The recovered denominator is always a divisor of r, equal to r only when s and r are coprime.
  6. The remedy is cheap: repeat the run. Different runs give different s, and either one run with s coprime to r appears, or combining two candidate denominators by their least common multiple (for example lcm(3, 4) = 12) reveals r.

The check step (compute aᶜ mod N for the candidate c and see whether it equals 1) is classical and takes microseconds. It is the reason failed runs cost only a repeat, not a wrong answer.

How big a machine? The 2019 and 2025 estimates

Resource estimates for RSA-2048 have fallen sharply over the years, and the assumptions behind them matter.

EstimatePhysical qubitsRun timeKey assumptions
Gidney and Ekerå, 2019 (published in Quantum, 2021)about 20 million noisy qubitsabout 8 hours10⁻³ gate error, 1 µs surface-code cycle, 10 µs reaction time, 2D grid with nearest-neighbour links
Gidney, May 2025 (arXiv:2505.15917)fewer than 1 million noisy qubitsless than a weekSame assumptions as 2019

Two published estimates for factoring a 2048-bit RSA number. Both assume large superconducting-style hardware.

The 2025 paper credits its improvement to several developments from other work: approximate residue arithmetic, which reduces the qubits needed for the arithmetic, yoked surface codes, which store idle logical qubits more efficiently, and magic state cultivation, which needs less space than magic state distillation. It also reports a Toffoli count more than 100 times lower than an earlier approach. The trade-off is a longer runtime, since there are more Toffoli gates in sequence and fewer magic state factories.

Worked example

Putting the numbers in perspective

  1. The largest chips discussed in these lessons have on the order of 100 physical qubits (Google’s Willow has 105). 20 million divided by 105 is about 190,000, so the 2019 estimate is roughly five orders of magnitude beyond today’s chips.
  2. 1 million divided by 105 is about 9,500, so the 2025 estimate is roughly four orders of magnitude beyond them.
  3. The estimates also assume a physical error rate of 10⁻³ everywhere, with a 1 µs cycle, which today’s best devices approach only for some operations and only on small systems.
  4. IBM’s roadmap targets a fault-tolerant system called Starling by 2029 with 200 logical qubits and 100 million operations. Compare with the roughly six thousand logical qubits and billions of Toffolis in the formula above: the roadmap’s target is an important step, but a much smaller machine than the one needed for RSA-2048.

How to read these numbers

An estimate is not a forecast. It says how big a machine of a given kind would have to be. It does not say when anyone will build it, and the hardware assumptions may or may not hold at scale. Equally, the steady drop in the estimates is a reason not to treat 2048-bit RSA as safe indefinitely. The sensible position, and the one security agencies have taken, is to plan the migration now.

What has actually been demonstrated? Experimental runs of Shor’s algorithm have been done only on toy numbers such as 15 and 21, and several of these used shortcuts that rely on knowing the answer in advance to simplify the circuit. I have not opened a primary source for each demonstration, so treat this summary as general knowledge, not a citation. They show that the logic works, but they are far from a scalable factoring machine.

Beyond RSA, and what Shor does not break

The same period-finding idea solves the discrete logarithm problem, which underlies classical Diffie–Hellman key exchange and elliptic-curve cryptography. These systems are therefore also vulnerable to a large quantum computer, and the Gidney–Ekerå paper treats both factoring and finite-field discrete logarithms. Elliptic-curve keys are much shorter than RSA keys for similar classical security, so published resource estimates for breaking them are smaller; I did not open those estimates for this lesson.

PrimitiveQuantum threatNotes
RSA, finite-field Diffie–Hellman, DSABroken by Shor in polynomial timeNeeds a large fault-tolerant machine
Elliptic-curve cryptography (ECDH, ECDSA)Broken by a variant of ShorShorter keys, so a smaller machine than for RSA of equal classical strength
AES and other symmetric ciphersGrover gives a quadratic speed-up on key searchDoubling the key length restores the margin: AES-256 is the usual recommendation
Hash functionsGrover-type attacks give a quadratic speed-up for preimagesLonger outputs restore the margin
Lattice-based and hash-based post-quantum schemesNo known efficient quantum attackSecurity is believed, not proven; they are the basis of the new standards

The response: post-quantum cryptography

On 13 August 2024 NIST announced the approval of its first three finalised post-quantum cryptography standards. FIPS 203 specifies a module-lattice-based key-encapsulation mechanism, derived from the CRYSTALS-Kyber submission. FIPS 204 specifies a module-lattice-based digital signature scheme, derived from CRYSTALS-Dilithium. FIPS 205 specifies a stateless hash-based signature scheme, derived from SPHINCS+. NIST describes them as designed to resist future attacks by quantum computers. The announcement itself sets no migration deadline.

Migration matters now because of the ‘harvest now, decrypt later’ threat: an adversary can record encrypted traffic today and decrypt it once a capable machine exists. Any data that must stay confidential for decades is therefore already exposed in principle. Systems are being updated to use the new schemes, often in a hybrid mode that combines a classical and a post-quantum algorithm, so that security holds if either is sound.

Common misunderstandings

MisunderstandingCorrection
Shor’s algorithm tries all factors at onceIt finds the period of aˣ mod N by interference. The factors then follow from classical gcd computations.
The quantum computer does all the workThe quantum part is period finding. Pre-processing, continued fractions and gcds are classical and cheap.
It always works in one runIt succeeds with constant probability per run, and the classical reduction fails for some choices of a. A few repeats suffice.
Factoring 15 or 21 on a quantum computer shows RSA is about to fallThose are toy numbers, and some demonstrations used shortcuts. RSA-2048 needs thousands of logical qubits.
Quantum computers break all encryptionThey break factoring and discrete-log schemes. Symmetric ciphers and the new post-quantum schemes are not broken by known quantum attacks.
Classical factoring is proven hardIt is believed hard. No proof exists, and a classical breakthrough is not ruled out.

Practice problems

Check yourself

Find the order of 2 modulo 15 and use it to factor 15.

Powers: 2, 4, 8, 16 ≡ 1, so r = 4. 2² = 4, gcd(4 − 1, 15) = 3 and gcd(4 + 1, 15) = 5. So 15 = 3 × 5.

Why does a = 14 fail for N = 15?

The order is 2 and 14¹ ≡ −1 (mod 15), so both gcds are trivial (1 and 15).

Find the order of 5 modulo 21 and factor 21 with it.

Powers of 5 mod 21: 5, 4, 20, 16, 17, 1, so r = 6. 5³ = 125 ≡ 20 ≡ −1 (mod 21), so this a fails.

Find the order of 4 modulo 21 and the factors it gives.

Powers: 4, 16, 64 ≡ 1, so r = 3, which is odd, so this a fails.

Why must the number of counting qubits satisfy 2ᵗ ≥ N²?

To make |y/Q − k/r| < 1/(2r²), so that the continued-fraction expansion of y/Q identifies k/r uniquely.

For N = 15, a = 7, Q = 16 you measure y = 8. What do you do?

8/16 = 1/2, so the candidate r = 2. Check 7² = 49 ≡ 4 ≠ 1, so it fails. Run again.

Using the Gidney–Ekerå formula, estimate the logical qubits for n = 1024.

3 × 1024 + 0.002 × 1024 × 10 = 3,072 + 20.5 ≈ 3,092.

The 2019 estimate is 20 million qubits and the 2025 estimate is under 1 million. What is the ratio, and what changed?

At least 20 times fewer qubits. New arithmetic methods, yoked surface codes and magic state cultivation, at the cost of a longer run time (under a week instead of about 8 hours).

Which NIST FIPS standard covers key encapsulation, and which two cover signatures?

FIPS 203 covers key encapsulation (ML-KEM, from Kyber). FIPS 204 (from Dilithium) and FIPS 205 (from SPHINCS+) cover signatures.

References and further reading

The explanations and all numerical examples (periods, gcds, measurement distributions, continued fractions, gate-count formulas) are written for this site and were computed directly. I opened the arXiv abstracts of Gidney and Ekerå (2019), Gidney (2025) and the NIST announcement of the first three post-quantum standards, and used the figures they state. Shor’s paper was checked for title and author only. The claim that classical factoring is super-polynomial is a standard belief, not a proven theorem.

  1. Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer (arXiv quant-ph/9508027, P. W. Shor) The original algorithm. Title and author checked; full text not re-read.
  2. How to factor 2048 bit RSA integers in 8 hours using 20 million noisy qubits (arXiv:1905.09749, C. Gidney and M. Ekerå; Quantum 5, 433 (2021)) Opened. Cost formulas and the 2019 estimate with assumptions.
  3. How to factor 2048 bit RSA integers with less than a million noisy qubits (arXiv:2505.15917, C. Gidney, May 21, 2025) Opened. Under 1 million qubits and under a week, with the same assumptions.
  4. Announcing Approval of Three Federal Information Processing Standards (FIPS) for Post-Quantum Cryptography (NIST, August 13, 2024) Opened. FIPS 203, 204 and 205; no migration deadline stated.
  5. Quantum algorithms: an overview (npj Quantum Information, A. Montanaro, 2016) Opened. O((log N)³) factoring cost and the super-polynomial speed-up statement.
  6. IBM Sets the Course to Build World’s First Large-Scale, Fault-Tolerant Quantum Computer (IBM Newsroom, June 10, 2025) Starling target: 200 logical qubits, 100 million operations by 2029.
  7. Meet Willow, our state-of-the-art quantum chip (Google, December 2024) 105-qubit chip used for scale comparison.
  8. Physics 219 Quantum Computation: lecture notes (John Preskill, Caltech) Free notes on order finding and Shor’s algorithm.