Skip to content
Adrien Hubert

Hamming(7,4), one bit off.

Four bits go in, seven come out. Three of the seven are parity bits, chosen so any single-bit flip on the wire can be located and undone. Click a data cell to change the message. Click any of the seven received cells to simulate noise. The three parity checks resolve into a three-bit number, and that number is the position of the flipped bit, in binary.

Data — four bits

encode ↓

Codeword sent — seven bits

0 p1 0 p2 0 d1 0 p4 0 d2 0 d3 0 d4
channel · click any cell to flip ↓

Received — click to introduce noise

s1
r1 ⊕ r3 ⊕ r5 ⊕ r7 (positions with bit-1 set)
0
s2
r2 ⊕ r3 ⊕ r6 ⊕ r7 (positions with bit-2 set)
0
s4
r4 ⊕ r5 ⊕ r6 ⊕ r7 (positions with bit-4 set)
0
Syndrome 000. No error detected.

Why the syndrome is the position

The parity bits sit at positions 1, 2 and 4 — the powers of two. Parity bit p1 covers every position whose index has bit 1 set (1, 3, 5, 7). Parity p2 covers every position whose index has bit 2 set (2, 3, 6, 7). Parity p4 covers every position whose index has bit 4 set (4, 5, 6, 7). When you flip a single bit at position k, the parity checks that fail are exactly those whose covered set contains k. The three pass/fail flags, read as s4·s2·s1 in binary, spell out k. A syndrome of zero means every check passed and no bit is off.

One flip only

The code corrects any single bit. Try two flips at once and the syndrome still points somewhere — but at the wrong position. The receiver will confidently flip a third, still-good bit, leaving the message worse than it arrived. Distance-three codes can detect two errors or correct one, never both. To handle more, you need more parity: Hamming(15,11) buys you room but still corrects only one, and the extended (8,4) SECDED variant adds an overall parity bit that catches (without correcting) the second flip.

Where the code came from

Richard Hamming was working on relay-based calculators at Bell Labs in the late 1940s. A parity check would tell him a card had failed on the weekend and the job had halted, but not where; on Monday he would rerun the batch. The idea of using several overlapping parity checks to name the failing bit came out of that frustration. He published the construction in 1950.

Sources

  • Hamming, R. W. (1950). Error detecting and error correcting codes. Bell System Technical Journal, 29(2), 147–160.
  • MacKay, D. J. C. (2003). Information Theory, Inference, and Learning Algorithms. Cambridge University Press. Chapter 1 walks through the (7,4) code cell by cell.