The Three-Qubit Bit-Flip Code
Classical computers guard against errors the obvious way: keep three copies of every bit and take a
majority vote. Quantum information seems to slam the door on that plan twice over. You
cannot copy an unknown qubit — the
no-cloning theorem
forbids it — and even if you could, reading a qubit to check it for errors
collapses
the very superposition you were trying to protect. So how can you ever repair a quantum state you are
not allowed to look at? The three-qubit bit-flip code is the first, and cleanest,
answer — the "hello world" of quantum error correction. Its trick is to measure the error
without ever measuring the message.
Encoding: spread one qubit across three
We want to protect a single logical qubit in an unknown state
|\psi\rangle = \alpha|0\rangle + \beta|1\rangle. Take two blank helper
qubits in |0\rangle and apply two
CNOT gates, both
controlled by our data qubit, targeting each helper in turn. The result is the
encoded (or logical) state
\alpha|0\rangle + \beta|1\rangle \;\longmapsto\; \alpha|000\rangle + \beta|111\rangle.
The two logical basis states are now
|0_L\rangle = |000\rangle and
|1_L\rangle = |111\rangle. Notice what did not happen: this is
not three copies of |\psi\rangle. Three copies would be
the product |\psi\rangle|\psi\rangle|\psi\rangle, which multiplies out to
eight terms; here we have only two, |000\rangle and
|111\rangle. The three qubits are entangled, not
duplicated — no single qubit on its own carries \alpha or
\beta. We have not dodged no-cloning; we have spread the
information out so that a single mishap can be voted down.
Worked example 1: running the encoder
Start with the data qubit in |\psi\rangle and two helpers in
|0\rangle, i.e. the three-qubit state
\big(\alpha|0\rangle + \beta|1\rangle\big)\otimes|0\rangle\otimes|0\rangle = \alpha|000\rangle + \beta|100\rangle.
Step 1 — CNOT from qubit 1 onto qubit 2. Each term flips its second bit exactly when
the first bit is 1. The \alpha term
(|000\rangle) is untouched; the \beta term
(|100\rangle) becomes |110\rangle:
\alpha|000\rangle + \beta|100\rangle \;\xrightarrow{\ \mathrm{CNOT}_{1\to2}\ }\; \alpha|000\rangle + \beta|110\rangle.
Step 2 — CNOT from qubit 1 onto qubit 3. Again only the
\beta term has a 1 in the control, so its third
bit flips too:
\alpha|000\rangle + \beta|110\rangle \;\xrightarrow{\ \mathrm{CNOT}_{1\to3}\ }\; \alpha|000\rangle + \beta|111\rangle.
Two gates, and the logical qubit is safely spread across three physical ones. The amplitudes
\alpha, \beta rode along untouched — we never learned or disturbed them.
Detecting a flip without looking at the data
Suppose noise flips one qubit — say a stray
bit-flip
(an X error) lands on qubit 2, turning our encoded state into
\alpha|010\rangle + \beta|101\rangle. We must not measure the data qubits
to find out — that would reveal (and destroy) \alpha and
\beta. Instead we ask two relative questions that never mention
the actual values:
- Do qubits 1 and 2 agree? This is the parity check
Z_1 Z_2.
- Do qubits 2 and 3 agree? This is the parity check
Z_2 Z_3.
Each check has outcome +1 when the two qubits agree and
-1 when they disagree. We extract it by CNOT-ing the two data
qubits onto a fresh ancilla qubit and then measuring only the ancilla. Writing each
result as a bit — 0 for "agree", 1 for "the
check fired" — the pair (s_1\, s_2) is called the syndrome.
Because a single flip changes exactly which neighbours disagree, the syndrome pins down the culprit:
| Error | Z_1 Z_2 | Z_2 Z_3 | Syndrome (s_1\, s_2) | Fix |
| none | +1 | +1 | 00 | — |
| qubit 1 | -1 | +1 | 10 | X on qubit 1 |
| qubit 2 | -1 | -1 | 11 | X on qubit 2 |
| qubit 3 | +1 | -1 | 01 | X on qubit 3 |
Here is the whole circuit — encode, then extract the two parities onto ancillas
a_1, a_2, then measure only the ancillas. Step through it:
Worked example 2: catch and fix a flip on qubit 2
Our state after the flip is \alpha|010\rangle + \beta|101\rangle. Run the
two parity checks on each branch of the superposition:
- |010\rangle: bits are 0,1,0. Qubits 1&2
differ (Z_1 Z_2 = -1); qubits 2&3 differ
(Z_2 Z_3 = -1).
- |101\rangle: bits are 1,0,1. Qubits 1&2
differ (Z_1 Z_2 = -1); qubits 2&3 differ
(Z_2 Z_3 = -1).
Both branches give the same answer, (-1, -1). That is the whole
magic: since the syndrome is identical on the \alpha and
\beta parts, measuring it tells us only the error and leaves the
superposition \alpha \,|\cdot\rangle + \beta\, |\cdot\rangle intact. The
ancillas report the syndrome
(s_1\, s_2) = (1, 1) \;\Longrightarrow\; \text{qubit 2 flipped.}
We apply the correction X to qubit 2, flipping its middle bit back:
\alpha|010\rangle + \beta|101\rangle \;\xrightarrow{\ X_2\ }\; \alpha|000\rangle + \beta|111\rangle.
The original encoded state is restored — \alpha and
\beta exactly as they were, never once observed.
Why the ancilla trick works
If you measured a data qubit directly you would project it to a definite
|0\rangle or |1\rangle with probabilities
|\alpha|^2, |\beta|^2 — you would learn a bit of the message and shatter
the superposition. The parity checks sidestep this because
Z_1 Z_2 and Z_2 Z_3 ask only whether qubits
match, a question whose answer is the same for |000\rangle and
|111\rangle (both "all agree"). So on the clean code the syndrome is
00 regardless of \alpha, \beta; a single flip
shifts it to one of the three non-zero patterns, and every branch of the state shifts together. The
measurement collapses the error onto a definite value while the encoded amplitudes ride
through untouched.
- Encode with two CNOTs:
\alpha|0\rangle + \beta|1\rangle \mapsto \alpha|000\rangle + \beta|111\rangle
(so |0_L\rangle=|000\rangle,
|1_L\rangle=|111\rangle). This entangles, it does
not clone — no single qubit holds \alpha,\beta;
- Diagnose by measuring the two parity checks
Z_1 Z_2 and Z_2 Z_3 via ancillas. The
syndrome reveals which qubit flipped, never
\alpha or \beta, and does not
collapse the superposition;
- Syndrome table:
00=none, 10=qubit 1,
11=qubit 2, 01=qubit 3; then apply
X to the flagged qubit to correct;
- Limits: it corrects at most one bit-flip, and fixes
only bit-flips (X) — phase-flips
(Z) are invisible to it.
This is the single idea that makes quantum error correction possible at all. A naive engineer, told a
qubit might have flipped, reaches for a voltmeter and looks — and in looking, destroys the fragile
superposition that was the whole point. The bit-flip code's genius is to ask a question the noise can
answer but the message cannot betray: not "what value is qubit 2?" but "do qubits 1 and 2 still
agree?" Agreement is a property of the relationship between qubits, shared identically by
every term of the superposition, so its measurement reveals the accident without revealing the
secret. Every code that came after — from Shor's to the surface code — is built on this same move:
design measurements (called stabilizers) that see only the errors and are blind to the
encoded data.
Do not oversell this code. First, it defends against exactly one kind of error:
bit-flips, the X Pauli. A phase-flip
(Z) sends \alpha|000\rangle + \beta|111\rangle
to \alpha|000\rangle - \beta|111\rangle, which every
Z-parity check still reads as "all agree" — the syndrome stays
00 and the corruption sails through completely undetected. (Fixing both
kinds at once takes nine qubits and the
Shor code.)
Second, it corrects at most a single flip: if two qubits flip, the majority
has moved, the syndrome points at the one innocent qubit, and "correcting" it produces a
logical error. The code is a genuine improvement only when single flips are far likelier than double
ones — which, for weak enough noise, they are.