Thought Toys · Computation & information · Exhibit 56

Catch one error, miss the next

Flip one bit anywhere in a 7-bit codeword and this trick finds it and fixes it — no hesitation, no ambiguity. Flip a second bit, though, and it just as confidently "fixes" something. Just not the right thing — and it hands back a message that looks every bit as legitimate as the real one.

Bit positions 1–7, sent · received · corrected parity data flipped by noise changed by decoder

Try it
your turn — drag noise up to 2 and watch it lie

What you're seeing

Four bits of real message ride inside a 7-bit codeword, padded out with three parity bits — each parity bit a running XOR of a different, overlapping subset of the other positions. Send it down a noisy line, and the receiver recomputes those three checks on whatever actually arrived. Read together, the three checks form a number from 0 to 7: the syndrome. Flip zero bits and the syndrome comes back exactly 0. Flip exactly one, anywhere in the seven, and the syndrome comes back as exactly that bit's position — not "there's an error somewhere," but "it's this one, right here." Flip it back and the original 4 data bits are sitting there again, untouched.

Now push the noise slider to 2. The syndrome still comes back as some confident number between 1 and 7 — the decoder never shrugs. But that number is now, provably, the wrong position: fixing it doesn't undo the damage, it adds a third change on top of the two real ones, landing on a completely different 4-bit message that looks exactly as legitimate as the one that was actually sent. There is no warning light. The only way to know something went wrong is to already know what the message was supposed to be — which, out in the real world, is exactly the one thing you never have.

The rule, exactly. Data bits sit at codeword positions 3, 5, 6, 7; parity bits sit at the powers of two, 1, 2, 4, each one the XOR of every position whose binary index shares that bit. The three recomputed checks, read as a binary number syndrome = c1 + 2c2 + 4c3, are exactly 0 for a clean codeword and exactly the flipped position for any single-bit error — never anything in between, never a false alarm. This works because Hamming(7,4) is a perfect code: the 128 possible 7-bit strings split into exactly 16 non-overlapping neighborhoods of radius 1 (1 center + 7 one-flip neighbors = 8 words, and 16 × 8 = 128 with nothing left over), one neighborhood per valid codeword. A single flip can only ever land inside the true neighborhood; two flips can walk the word into a different codeword's neighborhood entirely, where it looks perfectly at home. Verified in node (improve/verify/56-hamming.js): across every one of the 16 possible messages, all 128 zero-or-one-bit-flip cases recover the exact original data, the minimum distance between any two codewords is exactly 3, and all 336 possible two-bit-flip cases decode to a different, wrong message — 0 accidental matches. Counter-example: a decoder that simply refused to "correct" anything at all would at least be honest about a 2-bit error — instead, every real Hamming decoder reports full confidence on both an already-correct answer and a silently wrong one, using the identical code path; that is precisely why systems that must survive 2-bit errors add one more overall parity bit (SECDED) — upgrading "silently wrong" to "detected, but no longer fixable."

Also in Computation & information: Why more processors stop helping →

All 20 in Computation & information
  1. 101Noise sets a speed limit, not an accuracy limit.
  2. 111Any party of six hides a trio
  3. 120How one bit of ink makes a grey
  4. 125The ambulance that arrives sooner by going slower
  5. 131Every number is a sum of Fibonacci numbers
  6. 23Sorting algorithms
  7. 24PageRank & the random surfer
  8. 25Huffman coding
  9. 26Dijkstra's shortest path
  10. 33The learning-rate cliff
  11. 36A* pathfinding
  12. 44Diffie–Hellman key exchange
  13. 49Freeze too fast, stay stuck
  14. 56Catch one error, miss the next — you are here
  15. 57Why more processors stop helping
  16. 58Why a busy line explodes
  17. 59The set that's only sure when it says no
  18. 60The fit that memorizes instead of learns
  19. 61When the wire breaks, pick one
  20. 82Your computer can't hold one tenth

← the cabinet · Thought Toys — a cabinet of explorable explanations. Exhibit 56.