
A First Quantum Error-Correction Code: The Three-Qubit Repetition Code
The three-qubit repetition code shows how syndrome measurements can detect a bit flip without measuring the encoded logical value.
Imagine a program whose answer is stored in one fragile qubit. A stray interaction flips its state, and the result is no longer trustworthy. Classical computers handle a similar problem by storing a bit several times and taking a majority vote. The three-qubit repetition code brings that idea into quantum computing, while revealing why protecting a quantum state is more subtle than copying a bit.
Encode one qubit across three
Write an unknown qubit as (|\psi\rangle = \alpha|0\rangle + \beta|1\rangle). The repetition code encodes it as
[ |\psi_L\rangle = \alpha|000\rangle + \beta|111\rangle. ]
The subscripts on the encoded state simply remind us that this is a logical qubit represented by three physical qubits. The encoding does not make three independent copies of the unknown state. Instead, it entangles the original qubit with two helper qubits. In a circuit, two controlled-NOT gates can do this: use the state-carrying qubit as control and each helper, initially in (|0\rangle), as a target.
This is already a useful programming distinction. A logical value is not necessarily a value sitting in one variable or one wire. It can be a relationship among several physical qubits, and the program has to preserve that relationship.
Ask for a syndrome, not the answer
Suppose one physical qubit suffers a bit flip, represented by the Pauli (X) operation. To locate it, compare neighboring qubits for agreement. Quantumly, these checks are the parities (Z_1Z_2) and (Z_2Z_3). Each parity check returns whether its pair agrees or differs, but it does not reveal whether the encoded logical value was 000 or 111.
The pair of check outcomes is called the syndrome. Write 0 for agreement and 1 for disagreement. A flip on qubit 1 produces syndrome 10; a flip on qubit 2 produces 11; and a flip on qubit 3 produces 01. No flip gives 00. The pattern points to the likely faulty qubit, much like an error code in a data packet points to a corrupted position.
In a circuit, these checks can be extracted with helper qubits and then measured. The key idea is to measure the parity information, not the data qubits one by one. Measuring the data directly in the computational basis would collapse the superposition and destroy the encoded quantum information. The syndrome measurement instead distinguishes the error patterns while leaving the logical 0 and logical 1 branches indistinguishable.
Recover the state, then notice the catch
Once the syndrome identifies a single flipped qubit, apply (X) to that qubit. For example, syndrome 11 says the middle qubit differs from both neighbors, so the recovery applies (X_2). This restores the encoded state, assuming there was at most one bit flip and the check and recovery operations worked correctly.
The catch is that the code only checks computational-basis agreement. A phase flip, represented by (Z), changes the sign of one branch: (\alpha|000\rangle + \beta|111\rangle) becomes (\alpha|000\rangle - \beta|111\rangle) after a phase flip on one qubit. Both branches still have matching bits, so the two parity checks return 00. The error slips past this detector.
To see the complementary idea, switch basis with Hadamard gates. The encoded state becomes (\alpha|+++\rangle + \beta|---\rangle), where plus and minus are the X-basis states. In this basis, parity checks using pairs of X operations can detect a phase flip, much as the Z checks detect a bit flip. Protecting against arbitrary single-qubit errors requires combining bit-flip and phase-flip protection, as larger quantum error-correcting codes do.
A small code, not fault tolerance
The three-qubit repetition code is a teaching tool, not a complete shield for a quantum computer. It demonstrates how redundant encoding, syndrome extraction, and conditional recovery can correct one kind of error without measuring the logical answer. But it does not protect against phase flips, and a faulty gate or syndrome measurement can introduce errors of its own. Multiple errors can also produce a misleading syndrome and cause recovery to make things worse.
Fault-tolerant computing takes the next step: its code, measurements, and logical operations are arranged so that local failures do not spread uncontrollably, and error checks are repeated as needed. That costs more qubits and careful engineering. The three-qubit example is valuable precisely because it isolates the core loop: encode, measure what went wrong without learning the stored value, and repair only what the syndrome justifies. It is a compact first look at how quantum programs can reason about errors without peeking at the computation itself.