QUANTUM
COMPUTING ERA
Era
Logical Qubits
Era Clock
reveal 14 Apr 2027
Q-Day
 
Crowd
vote open
Q-Day guide

Home / Q-Day / Shor's algorithm

Shor's algorithm

Shor's algorithm is a recipe that lets a quantum computer find the prime factors of a large number in far fewer steps than any known classical method. Peter Shor published it in 1994, and it is the reason RSA and elliptic curve encryption are expected to fail once a large enough quantum computer exists.

Updated 8 November 2026. Every figure links to its source below.

The problem it solves

Multiplying two large prime numbers is easy, and recovering them from the product is hard. RSA encryption depends on that gap. The best known classical method for factoring takes time that grows faster than any polynomial in the number of digits, so a 2048-bit RSA number stays out of reach of every computer built.

Shor showed in 1994 that a quantum computer could factor in time that grows only polynomially with the number of digits. He also gave a fast method for the discrete logarithm problem behind Diffie-Hellman, and the same approach adapts to elliptic curves. One family of algorithms therefore threatens all three of the public-key systems in everyday use.

The idea in plain words

Shor's algorithm turns factoring into a different question, which is to find how often a certain pattern repeats. Pick a number a that shares no factor with N, the number to be factored. The values of a, a squared, a cubed and so on, each taken modulo N, eventually return to 1. The number of steps before that happens is called the period, or the order of a.

If r is even, and a to the power r/2 is not equal to minus 1 modulo N, simple arithmetic turns it into factors of N. Otherwise you pick another a, and for random choices this works at least half the time. The hard part is finding r. The quantum machine puts its input register into a superposition and computes the pattern once across it, coherently. Measuring directly would give one random value and reveal nothing, so it first applies a quantum Fourier transform, which uses interference to make outcomes tied to the period far more likely. Hidden periodic structure like this is one of the few things a quantum computer is known to find much faster than a classical one. A normal computer finishes the job with a greatest common divisor, a step it can do quickly.

A worked example with 15

Take N = 15 and choose a = 7. The powers of 7 modulo 15 are 7, 4, 13 and 1, so the period is r = 4. You can check this by hand, since 7 squared is 49, which is 4 more than 45, and 7 to the fourth power is 2,401, which is 1 more than 2,400.

  1. The period 4 is even, so compute 7 to the power 4 divided by 2, which is 7 squared, or 49.
  2. Find the greatest common divisor of 49 minus 1 and 15. That is gcd(48, 15), which is 3.
  3. Find the greatest common divisor of 49 plus 1 and 15. That is gcd(50, 15), which is 5.

The factors of 15 are 3 and 5. For a large N the only slow step is finding r, because the classical steps around it are quick. Shor's insight was that a quantum computer can find r without checking each candidate in turn.

The algorithm does not work by trying every answer at once. The machine holds many inputs together, but a measurement returns only one. The answer emerges because interference cancels the unhelpful outcomes and strengthens the useful ones.

What experiments have shown

In 2001 a team at IBM and Stanford used a seven-qubit nuclear magnetic resonance machine to factor 15, using the same a = 7 as the example above, as reported in Nature. In 2012 a photonic experiment factored 21, using a qubit that was recycled during the run. These were milestones for the field and not threats to any key.

Critics have argued that such demonstrations prove less than they appear to. John Smolin, Graeme Smith and Alex Vargo showed in 2013 that a compiled version, which builds in knowledge of the answer, can appear to factor far larger numbers using almost no quantum resources. A fair test needs an uncompiled circuit with error correction, and that is the machine the fault tolerance tracker follows.

What it would take at full size

Factoring a 2048-bit number needs a very long, very precise calculation. Errors build up in every physical qubit, so the machine needs error correction and many physical qubits per logical one. In 2025 Craig Gidney estimated fewer than a million noisy physical qubits and under a week. The guide to qubits needed to break RSA explains the figure and its assumptions.

The wider consequences are in the Q-Day overview. The change to new encryption is covered in post-quantum cryptography.

Questions

Quick answers

What does Shor's algorithm do?

It finds the prime factors of a large number, and it solves the related discrete logarithm problem, in a number of steps that grows only polynomially with the size of the number. The best known classical methods grow much faster.

Does a quantum computer try every possible factor at once?

No. The machine prepares many inputs together, but a measurement returns only one result. The algorithm uses interference so that the results that reveal the repeating pattern become far more likely than the rest.

What is the largest number factored with Shor's algorithm?

Published experiments have factored only tiny numbers, 15 in 2001 and 21 in 2012. Critics note that several of these demonstrations used shortcuts that depend on knowing the answer, so they prove less than the numbers suggest.

Does Shor's algorithm also break elliptic curves?

Yes. Shor's method also solves the discrete logarithm problem behind Diffie-Hellman, and the approach adapts to elliptic curves. This is why one family of algorithms threatens RSA, Diffie-Hellman and elliptic curve cryptography.

Does Shor's algorithm break AES?

No. Shor's algorithm attacks the structure of RSA and elliptic curve maths. Grover's algorithm speeds up brute-force key search only quadratically and does not parallelise well, and NIST says it is quite likely to give little or no advantage against AES.

Sources

Where these numbers come from

  1. Shor, Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer (1994, SIAM Journal on Computing 1997)
  2. Vandersypen and others, Experimental realization of Shor's quantum factoring algorithm using nuclear magnetic resonance (Nature, 2001)
  3. Martín-López and others, Experimental realization of Shor's quantum factoring algorithm using qubit recycling (Nature Photonics, 2012)
  4. Smolin, Smith and Vargo, Pretending to factor large numbers on a quantum computer (2013). Argues that compiled demonstrations of Shor's algorithm prove little
  5. Gidney, How to factor 2048 bit RSA integers with less than a million noisy qubits (2025)
  6. NIST, post-quantum cryptography FAQ. On Grover's algorithm and AES
Keep reading

More on Q-Day