THE QUANTUM THREAT / ADVANCED

Inside Shor's Algorithm, Without The Maths

How Shor's algorithm turns factoring into a search for a repeating pattern, which part needs a quantum computer, and why error correction rather than the algorithm is the real obstacle.

Checked against primary sources and independently reviewed on . Sources are listed at the end.

Shor’s algorithm is often described as “trying every answer at once”. That description is wrong, and it hides the interesting part. Most of the algorithm is ordinary number theory that runs on a normal computer. The quantum computer does one specific job: it finds the length of a repeating pattern far faster than any known classical method.

This article walks through the steps for factoring an RSA modulus, uses a tiny worked example, and then explains why building a machine that can run it on a 2048-bit key is mostly an engineering problem about errors. It assumes you have read Shor, Grover And What Quantum Computers Actually Break.

Factoring Is Really Pattern Finding

The key idea predates Shor. If you can find a quantity called the order of a number, you can usually factor. Pick a number x smaller than the modulus n that shares no factor with it. Now compute x, x squared, x cubed and so on, each time keeping only the remainder after dividing by n. The remainders eventually repeat in a cycle. The length of that cycle, the smallest r for which x to the power r leaves remainder 1, is the order.

Shor’s paper notes that factoring reduces to order finding by a randomised method published by Miller in 1976.1 Once r is known, and if it is even, the greatest common divisor of n and x to the power r/2 minus 1 often reveals a factor. Greatest common divisors are cheap to compute with Euclid’s algorithm. The only hard part is finding r, because for a 2048-bit n the cycle is astronomically long.

The Steps, Classical And Quantum

  1. Pick A Random Number x

    Classical. If x happens to share a factor with n, you are done already, which is very unlikely for RSA-sized numbers.

  2. Design The Circuit

    Classical. Plan a quantum circuit that computes x to the power a, modulo n, for a chosen range of exponents a.

  3. Compute Every Power In Superposition

    Quantum. Put the exponent register into a superposition of all exponents, then run the modular exponentiation circuit once on it. This is the expensive part.

  4. Apply The Quantum Fourier Transform And Measure

    Quantum. The transform makes the repeating pattern interfere with itself. Divided by the size of the register, the measured number is likely to sit close to a fraction whose denominator is r.

  5. Recover r With Continued Fractions

    Classical. A continued fraction expansion of that ratio gives a candidate for r. If it fails, repeat the quantum step.

  6. Compute The Factors

    Classical. Use greatest common divisors with x to the power r/2 plus or minus 1 to split n into its prime factors.

Shor’s factoring algorithm. Only steps three and four need a quantum computer; the rest is classical arithmetic.

The phrase “trying every answer at once” misleads because measurement returns only one result. The quantum Fourier transform matters because it arranges the computation so that wrong answers cancel and answers related to the period reinforce each other. Shor’s paper describes an efficient circuit for this transform and the continued fraction step that follows.1 For discrete logarithms, which underpin Diffie-Hellman and elliptic curve cryptography, the same paper gives a variant that uses two Fourier transforms over two registers.1

Why The Hard Part Is Errors

Every step above assumes the quantum computer is perfect. Real qubits are not. They lose their state through noise, and every gate adds a little error. A 2048-bit factoring circuit needs billions of operations, so even a tiny error rate per operation would ruin the result without correction.

The fix is quantum error correction. Many noisy physical qubits are combined to act as one reliable logical qubit, with constant checks that detect and undo errors faster than they build up. The algorithm runs on logical qubits; the hardware has to supply physical ones.

  1. AlgorithmShor’s algorithm for a 2048-bit RSA modulus or a 256-bit elliptic curve.
  2. Logical OperationsMeasured in logical qubits and in counts of expensive gates such as Toffoli gates.
  3. Error CorrectionCodes such as the surface code turn hundreds or thousands of physical qubits into one logical qubit.
  4. Physical QubitsSuperconducting circuits, trapped ions or neutral atoms, each with its own error rate, speed and connectivity.
How a fault-tolerant quantum computer is organised. Resource estimates quote numbers at more than one of these layers, so always check which one is meant.

The overhead is large. Craig Gidney’s May 2025 estimate for RSA-2048 needs 1,399 logical qubits and about 6.5 billion Toffoli gates.2 A Toffoli gate is an operation on three qubits that is expensive to carry out with error correction, so estimates count them as a measure of total work.

The physical layout shows where the qubits go. At the busiest point of the run the paper counts 1,409 logical qubits in use. The 1,280 that hold the input sit idle in a dense storage scheme at about 430 physical qubits each, while the qubits doing the work use standard surface code patches of 1,352 physical qubits each. Counting the spare patches in the area where computation happens, the layout holds 1,537 logical qubits, which the paper describes as fewer than 1,600, and about 900,000 physical qubits, which it rounds up to one million for safety. All of this assumes a 0.1 percent physical error rate and a one microsecond correction cycle.2

For comparison, a 2012 introduction to surface code computing by Fowler and colleagues estimated that factoring a 2000-bit number would need about a billion physical qubits running for about a day, at the same 0.1 percent error rate.3 Most of the improvement since then has come from smarter circuits and error correction, not from a new version of Shor’s idea.

Where Hardware Stands

Error correction only helps when physical errors are below a threshold; otherwise adding qubits makes things worse. In December 2024 Google reported that its 105-qubit Willow chip had crossed that threshold, with logical error rates halving each time the code grew from a 3 by 3 to a 5 by 5 to a 7 by 7 grid.4 That is an important step, but it involves around a hundred physical qubits against the tens of thousands to about a million that current estimates require, depending on the design. How those estimates have fallen is the subject of How Many Qubits To Break RSA.

Footnotes

  1. P. W. Shor, “Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer”, arXiv quant-ph/9508027, submitted 30 August 1995. arxiv.org ↩ ↩2 ↩3

  2. C. Gidney, “How to factor 2048 bit RSA integers with less than a million noisy qubits”, arXiv 2505.15917, 21 May 2025, section 3 and table 5. arxiv.org ↩ ↩2

  3. A. G. Fowler, M. Mariantoni, J. M. Martinis and A. N. Cleland, “Surface codes: Towards practical large-scale quantum computation”, arXiv 1208.0928, August 2012, revised October 2012. arxiv.org ↩

  4. Google, “Meet Willow, our state-of-the-art quantum chip”, 9 December 2024. blog.google ↩

Knowledge Hub content is general information. It is not legal advice, a compliance certification, a guarantee of security or a substitute for an assessment of your own systems. Standards and rules change; check the sources for the latest position.