Quantum
Module 8 · Noise and error correction · Lesson 2

The 3-qubit repetition code

The first quantum error-correcting code. Handles single bit-flip errors — by encoding one logical qubit into three physical qubits and measuring cleverly.

10 min read · Lesson 29 of 32

The 3-qubit bit-flip repetition code is the simplest possible quantum error correcting code. It can correct one bit-flip error (but not phase-flip errors, we’ll get to that). It’s the “hello world” of quantum error correction and the clearest way to see how the tricks work.

The encoding

We take one logical qubit in state ψ=α0+β1|\psi\rangle = \alpha|0\rangle + \beta|1\rangle and encode it as a 3-qubit state:

ψL=α000+β111|\psi\rangle_L = \alpha|000\rangle + \beta|111\rangle

Notice: this is not three copies of ψ|\psi\rangle. That would be ψ3|\psi\rangle^{\otimes 3}, which expands to eight terms and is forbidden by no-cloning anyway. What we have is an entangled state where the three physical qubits are correlated — and that correlation is what protects the logical information.

The encoding is done with a simple circuit: start with ψ00|\psi\rangle|0\rangle|0\rangle, apply CNOT from qubit 0 to qubit 1, then CNOT from qubit 0 to qubit 2. The result is ψL|\psi\rangle_L.

The correction

Suppose a bit-flip error hits qubit 1 (an unwanted XX gate). The state becomes:

α010+β101\alpha|010\rangle + \beta|101\rangle

We want to detect which qubit was flipped without learning α\alpha or β\beta — if we learn those, we collapse the logical state and destroy it.

The trick: measure syndromes. Specifically, measure the two operators Z0Z1Z_0 Z_1 and Z1Z2Z_1 Z_2 (the product of two ZZ operators). These measurements don’t tell you the value of any individual qubit; they only tell you parity — whether two specific qubits agree or disagree.

Here’s the syndrome table:

ErrorZ0Z1Z_0 Z_1Z1Z2Z_1 Z_2Diagnosis
No error+1+1+1+1Nothing to fix
XX on qubit 01-1+1+1Apply XX to qubit 0
XX on qubit 11-11-1Apply XX to qubit 1
XX on qubit 2+1+11-1Apply XX to qubit 2

Each single-qubit error produces a distinct syndrome, and the syndrome can be measured without disturbing the logical state. Apply the appropriate correction, and the logical qubit is restored — the errors have been corrected.

Try it

Pick an error to inject. Watch the 3-qubit state change. Then jump to the “Corrected” stage and watch the state return to its original form. The logical information never leaked; the correction was applied blindly based only on the syndrome.

What the code can and can’t do

Can do:

Can’t do:

The symmetric situation applies if you use a phase-flip repetition code (encoding in the XX basis instead of the ZZ basis) — it corrects ZZ errors but not XX errors.

Why this matters

The 3-qubit code is the simplest working example of the “syndrome measurement” technique, which is the fundamental idea behind all quantum error correction. Every more sophisticated code — the Shor code, the Steane code, the surface code — uses the same pattern:

  1. Encode logical qubits into entangled multi-qubit states within a carefully chosen “codespace.”
  2. Repeatedly measure specific parity-like operators that detect errors without touching the logical state.
  3. Apply corrections based on the syndrome.

The difficulty is building codes that handle all single-qubit errors (not just bit-flips) and scale to large logical qubits. The 3-qubit code is a stepping stone; the next lesson introduces codes that handle both bit-flip and phase-flip errors simultaneously.

Quick check
What is the 3-qubit repetition code's encoding of α|0⟩ + β|1⟩?
Quick check
What is a 'syndrome measurement'?
Quick check
Can the 3-qubit bit-flip repetition code correct phase-flip errors?

What’s next

The Shor and Steane codes handle both bit-flip and phase-flip errors by concatenating two repetition codes. The basic idea: encode into a phase-flip code, then encode each qubit of that into a bit-flip code. The result uses more physical qubits per logical qubit, but catches all single-qubit errors.