Resource Requirements
Every practical question about quantum advantage comes down to resources: how many qubits does the algorithm need, and how many elementary gates must those qubits execute reliably? For Shor's algorithm, both answers are polynomial in , the bit-length of the number to be factored. This lesson derives the estimates from first principles and puts them in the context of current hardware.
Qubit count
The period-finding circuit uses two registers.
Input register. We need qubits so that the QFT window satisfies . This ensures the continued-fraction step succeeds with constant probability. Since , we have , so qubits are sufficient and necessary.
Work (ancilla) register. Storing the value requires at most qubits, because and .
Additional ancilla. The reversible circuits that implement modular multiplication need extra workspace to avoid overwriting inputs. Efficient implementations use ancilla qubits; the exact constant depends on the chosen adder design.
Putting these together, the logical qubit count is
For the textbook target of cracking -bit RSA (), this is roughly to logical qubits, depending on the circuit optimisation.
Gate count
The three algorithmic stages contribute the following gate counts.
Hadamard layer
Applying to initialise the input register costs exactly single-qubit gates — negligible compared with the other stages.
Modular exponentiation
The modular-exponentiation oracle is implemented as a sequence of controlled modular multiplications: for each bit of the exponent, apply a modular multiplication by controlled on qubit . Each such multiplication is built from modular additions, which in turn use Toffoli gates and ancilla qubits. The total gate count for modular exponentiation is therefore
This is the dominant term in the gate budget.
Inverse QFT
The -qubit inverse QFT requires
rotation gates and Hadamards. This is a lower-order contribution compared with from modular exponentiation, but it must be implemented to very high precision since the rotation angles scale as for up to .
Total gate complexity
Combining the three stages,
The exact leading coefficient depends on the modular arithmetic implementation; optimised circuits achieve roughly Toffoli gates for practical implementations.
Concrete numbers for RSA-2048
For with bits, the estimates are:
| Resource | Order of magnitude | |---|---| | Logical qubits | | | Toffoli gates | | | T-gates (fault-tolerant) | | | Physical qubits (surface code, low noise) | |
The T-gate count is an order of magnitude larger than the Toffoli count because each Toffoli decomposes into T-gates in the Clifford+T basis, and fault-tolerant T-gate injection adds further overhead.
Circuit depth
Beyond gate count, the circuit depth (the critical path when gates are parallelised) matters because shallow circuits are less exposed to decoherence. With full parallelisation, the depth of modular exponentiation can be reduced from to using carry-lookahead adders. The QFT depth reduces to with nearest-neighbour architectures. In practice, the achievable depth depends heavily on the qubit connectivity graph of the hardware.
Why polynomial is not the same as easy
A gate count of is polynomial and therefore asymptotically efficient, but the constants matter. At the raw Toffoli count exceeds operations, each of which must succeed with extremely high fidelity under fault-tolerant encoding. Current superconducting processors execute two-qubit gates reliably before errors accumulate. The gap between today's devices and Shor-capable hardware is a central driver of post-quantum cryptography standardisation.
Comparing the two registers
The input register ( qubits) is larger than strictly necessary to hold the exponent ( bits) because the QFT must operate over a window at least to give the continued-fraction algorithm enough resolution to distinguish nearby fractions . Specifically, if and two valid approximations and differ by at least , then their integer encodings differ by at least , making them distinguishable after a single measurement. This is why — not — qubits are the right size for the input register.
Summary
Shor's algorithm factors an -bit number using:
- logical qubits (roughly in a careful count),
- elementary quantum gates (dominated by modular exponentiation),
- repetitions on average to extract from continued-fraction approximations.
All three quantities grow polynomially in , establishing a provably exponential advantage over the best known classical factoring algorithms. The remaining gap to practical deployment is engineering rather than algorithmic: building fault-tolerant logical qubits at scale.
Sign in on the full site to ask questions and join the discussion.