Hamming Codes: Correcting a Single-Bit Error
← All articles

Hamming Codes: Correcting a Single-Bit Error

6 min

Parity detects, but doesn't locate

A single parity bit tells you a transmitted word has an odd number of flipped bits — it says nothing about which bit. Hamming's insight was to use several parity bits, each covering a carefully chosen, overlapping subset of the data bits, so the specific pattern of which parity checks fail encodes the position of the bad bit directly.

Overlapping coverage

Each parity bit covers a different subset of positions, chosen so that every data bit ends up checked by a unique combination of parity bits. In the standard scheme, parity bit p1 covers every position whose binary index has bit 0 set, p2 covers every position with bit 1 set, p4 covers every position with bit 2 set, and so on — each data bit is checked by exactly the parity bits matching the 1-bits of its own position number.

p1p2p41243567

The syndrome points at the culprit

On receipt, recompute each parity bit the same way and XOR each recomputed value against the transmitted one. Stack the resulting mismatch bits together (p1's mismatch as bit 0, p2's as bit 1, and so on) and the result — the syndrome — is the binary position number of the single flipped bit, or all-zero if nothing flipped. A small decoder turns that syndrome directly into a one-hot 'flip this bit' signal.

Try it yourself

Build the parity-check XOR gates for a small Hamming-encoded word in the circuit editor, flip exactly one data bit with an INPUT switch, and confirm the resulting syndrome bits — read off a few OUTPUT elements — spell out the binary position of the bit you flipped.

Build a Hamming-encoded word in the circuit editor →