Why the quantum Fourier transform reveals the period
How a superposition and a Fourier transform turn a hidden period r into peaks at multiples of Q/r.
10 min read · reviewed December 2026
The circuit in words
- A counting register of t qubits is put into an equal superposition of all x from 0 to Q−1, where Q = 2^t.
- A work register is set to a^x mod N, computed for all x in superposition (modular exponentiation).
- The work register is measured. The counting register now holds only those x that give the measured value. Those x are spaced r apart: x₀, x₀ + r, x₀ + 2r, …
- The quantum Fourier transform is applied to the counting register, and it is measured. The outcome y is almost always close to a multiple of Q/r.
Interference does the work
A regular comb of amplitudes spaced r apart has a Fourier transform that is also a comb, spaced Q/r apart. Amplitudes at the comb positions add up, and amplitudes elsewhere cancel. The starting offset x₀ changes only a phase, so it does not move the peaks. That is why the unknown x₀ left over from measuring the work register does not matter.
P(y) = (1/Q²) · Σ over x₀ of | Σ_k e^(2πi · y · r · k / Q) |²
The actual distribution for N = 15
Here r = 4 and Q = 256 divides evenly, so all the weight lands exactly on 0, 64, 128 and 192, a quarter each. The lab computes this distribution exactly, from the formula above, and checks it against a direct Fourier-transform calculation.
| y | y/Q | Probability | Recovered r |
|---|---|---|---|
| 0 | 0.0000 | 25.0% | none (y = 0) |
| 62 | 0.2422 | 0.0% | 4 |
| 64 | 0.2500 | 25.0% | 4 |
| 126 | 0.4922 | 0.0% | 4 |
| 128 | 0.5000 | 25.0% | 4 |
| 192 | 0.7500 | 25.0% | 4 |
When Q/r is not a whole number
For N = 21 and a = 2 the period is 6 and Q = 512, so the peaks are at 512k/6, which are not integers. The weight then spreads over the two nearest integers, and the peaks are slightly lower and wider. This is why Q is chosen at least N²: so the nearest integer to k·Q/r is close enough for the continued-fraction step to recover r.
Try it
Questions
Why is the work register measured?
Measuring it collapses the counting register onto one regular comb. The measured value itself is discarded; it only serves to make the comb.
Does the algorithm need the work register measured at all?
Not strictly. Measuring it first or leaving it for later gives the same distribution for y. The lab uses the first picture because it is easier to follow.
Why a Fourier transform and not another transform?
Because the Fourier transform turns a periodic comb into another comb, which is the property needed. It also has an efficient quantum circuit.
Read next
Sources and further reading
- P. W. Shor, “Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer” (SIAM J. Comput. 1997, arXiv:quant-ph/9508027)
- M. Nielsen and I. Chuang, Quantum Computation and Quantum Information, chapter 5
- C. Gidney and M. Ekerå (2021), “How to factor 2048 bit RSA integers in 8 hours using 20 million noisy qubits”
- C. Gidney (2025), “How to factor 2048 bit RSA integers with less than a million noisy qubits”
- Algorithm page: Shor’s algorithm
Check the original sources for exact citations.