Phase flips and the Shor code
How to protect against Z errors by switching bases, and how nesting two repetition codes gives the first full quantum code.
9 min read · reviewed December 2026
A phase flip is a bit flip in another basis
Apply Hadamard gates to all three qubits of the bit-flip code. Now the roles of X and Z swap: a phase flip in the original basis acts like a bit flip, and the same two parity checks, rewritten in the new basis, catch it. This gives a 3-qubit code that corrects one phase flip and no bit flips.
Nesting the two
Peter Shor’s 1995 code does both at once. It uses nine qubits in three blocks of three. Inside each block, a bit-flip repetition code repairs X errors. Across the three blocks, a phase-flip repetition code repairs Z errors. A Y error is both, and both layers handle their half.
| Code | Generators |
|---|---|
| 3-qubit repetition | ZZI IZZ |
| 5-qubit code | XZZXI IXZZX XIXZZ ZXIXZ |
| Steane 7-qubit code | IIIXXXX IXXIIXX XIXIXIX IIIZZZZ IZZIIZZ ZIZIZIZ |
| Shor 9-qubit code | ZZIIIIIII IZZIIIIII IIIZZIIII IIIIZZIII IIIIIIZZI IIIIIIIZZ XXXXXXIII IIIXXXXXX |
How well does it work?
Under independent X, Y and Z errors the lab finds that every single-qubit error is fixed. Of the 324 possible two-qubit errors, 117 still cause a logical error. The other two-qubit errors are harmless, for a reason the decoding guide explains.
| Code | [[n,k]] | Checks | Single-qubit errors fixed | Two-qubit errors that fail | Beats no code up to |
|---|---|---|---|---|---|
| 3-qubit repetition | [[3,1]] | 2 | not all | 18 of 27 | never |
| 5-qubit code | [[5,1]] | 4 | all | 90 of 90 | 13.76% |
| Steane 7-qubit code | [[7,1]] | 6 | all | 147 of 189 | 8.10% |
| Shor 9-qubit code | [[9,1]] | 8 | all | 117 of 324 | 10.48% |
Try it
Questions
Why nine qubits?
Three for the bit-flip layer times three for the phase-flip layer. Smaller codes with the same distance exist, such as the 5-qubit code.
Does the Shor code correct every error?
Every single-qubit error. Two simultaneous errors can defeat it.
Why was Shor’s code a big deal?
It showed that quantum error correction is possible at all, which had been in serious doubt.
Read next
Sources and further reading
- P. W. Shor, “Scheme for reducing decoherence in quantum computer memory” (1995)
- A. M. Steane, “Error correcting codes in quantum theory” (1996)
- D. Gottesman, “Stabilizer codes and quantum error correction” (PhD thesis, 1997)
- Google Quantum AI, “Quantum error correction below the surface code threshold”
- M. Nielsen and I. Chuang, Quantum Computation and Quantum Information, chapter 10
Check the original sources for exact citations.