Error Correcting Codes: Complete Beginner's Guide Guide.
Error-correcting codes add designed redundancy so receivers can detect and fix bit errors from noisy channels — no retransmission needed. Two landmarks define the field: Hamming codes, which correct any single-bit error per block, and CRC (Cyclic Redundancy Check), which detects burst errors with remarkable reliability. They protect everything from RAM to Ethernet frames to satellite links.
Noise is unavoidable — cosmic rays flip RAM bits, interference corrupts wireless packets. Retransmission is impossible for broadcasts and too slow for deep space, so forward error correction is the only option. Hamming and CRC are the minimal, beautiful examples every engineer should work by hand.
Key Concepts
- Hamming (7,4): 4 data + 3 parity bits. Parity bits sit at positions 1, 2, 4; data fills 3, 5, 6, 7. Even parity is standard.
- Parity coverage: p1 covers 1,3,5,7; p2 covers 2,3,6,7; p4 covers 4,5,6,7 — each data bit gets a unique coverage pattern, which is the whole trick.
- Syndrome: recompute the three parities at the receiver; the pattern (s4 s2 s1) as binary is the error position. 000 means clean.
- Distance 3: codewords differ in ≥3 positions → correct 1 error, detect 2. Extended (8,4) with overall parity is what ECC RAM uses.
- CRC: treat the message as a polynomial, divide by a generator polynomial, append the remainder. The receiver re-divides: zero remainder means (probably) no error.
- Strength: an n-bit CRC catches all bursts up to n bits and all odd-weight errors (with a good generator) — why Ethernet uses CRC-32.
Formulas
Parity-bit rule: for m data bits need r with 2^r ≥ m + r + 1 (m = 4 → r = 3, since 8 ≥ 8). Code rate = 4/7 ≈ 0.57. Even-parity equations: p1 = d1⊕d2⊕d4, p2 = d1⊕d3⊕d4, p4 = d2⊕d3⊕d4 (⊕ = XOR; d1–d4 at positions 3,5,6,7). For CRC with degree-n generator G(x): append n zeros, XOR-divide by G(x), transmit message + n-bit remainder. The teaching generator is x³ + x + 1 (1011).
Worked Example
Encode data 1011 in Hamming (7,4), corrupt it, repair it. Step 1: positions 3,5,6,7 ← 1,0,1,1 (d1=1, d2=0, d3=1, d4=1). Step 2: p1 = 1⊕0⊕1 = 0; p2 = 1⊕1⊕1 = 1; p4 = 0⊕1⊕1 = 0. Step 3: codeword positions 1–7 → 0110011. Step 4: flip bit 6 → received 0110001. Step 5: syndrome. s1 = parity(1,3,5,7) = 0,1,0,1 → even → 0. s2 = parity(2,3,6,7) = 1,1,0,1 → odd → 1. s4 = parity(4,5,6,7) = 0,0,0,1 → odd → 1. Syndrome 110 = 6. Step 6: flip bit 6 back → 0110011, data 1011 recovered. CRC bonus: message 1010, generator 1011: append 000 → 1010000, XOR-divide → remainder 011, transmit 1010011.
Common Misconceptions
- "Hamming fixes any error." (7,4) corrects exactly one bit per block — two errors can miscorrect to the wrong position.
- "CRC corrects errors." CRC is detection-only; bad frames are discarded and (usually) retransmitted. Correction needs Hamming, Reed-Solomon or LDPC.
- "More redundancy is always safer." Redundancy costs bandwidth and power — real systems match code rate to the channel.
Real-World Applications
- ECC RAM: extended Hamming (72,64) silently fixes single-bit flips in servers.
- Ethernet/Wi-Fi: CRC-32 guards every frame.
- QR codes: Reed-Solomon (Hamming's descendant) recovers damaged symbols.
- Deep space: concatenated codes let Voyager's faint signals cross the solar system.
Hamming codes locate errors with overlapping parities — the syndrome literally names the faulty position — while CRC's polynomial division catches the burst errors real channels produce. One corrects, one detects; together they explain why digital communication survives a noisy universe.