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.

The stabilizer generators of each code. Each check is a product of Pauli operators; an error that anticommutes with it sets an alarm.
CodeGenerators
3-qubit repetitionZZI IZZ
5-qubit codeXZZXI IXZZX XIXZZ ZXIXZ
Steane 7-qubit codeIIIXXXX IXXIIXX XIXIXIX IIIZZZZ IZZIIZZ ZIZIZIZ
Shor 9-qubit codeZZIIIIIII 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.

The four codes in the lab, analysed over all 4^n Pauli errors with a lowest-weight lookup decoder.
Code[[n,k]]ChecksSingle-qubit errors fixedTwo-qubit errors that failBeats no code up to
3-qubit repetition[[3,1]]2not all18 of 27never
5-qubit code[[5,1]]4all90 of 9013.76%
Steane 7-qubit code[[7,1]]6all147 of 1898.10%
Shor 9-qubit code[[9,1]]8all117 of 32410.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

Check the original sources for exact citations.