1. Repetition & Parity
The simplest error detection and correction
Data in the real world gets corrupted. Bits flip in memory due to cosmic rays. Signals garble on copper wires and radio links. Storage media degrades over time. Every system that moves or stores data must confront the same problem: errors happen, and we need a way to detect them — and ideally fix them. The simplest ideas humanity devised for this are repetition and parity.
The Noisy Channel
In 1948, Claude Shannon formalized the problem with a model that still guides engineering today. The communication pipeline looks like this:
Shannon's Noisy Channel Model
Sender → Encoder → [ Noisy Channel ] → Decoder → Receiver
The encoder takes the original message and adds carefully chosen redundancy before transmission. The noisy channel is where errors creep in — a flipped bit, a dropped packet, a scratched disc. The decoder examines the received data, uses the redundancy to detect or correct errors, and delivers the cleaned-up message to the receiver.
The key insight of Shannon's work is that redundancy is not waste — it is the price of reliability. The question is how to spend it efficiently.
Repetition Codes
The most obvious form of redundancy: say everything three times. To send a
1, transmit 111. To send a 0, transmit
000. The decoder takes a majority vote on each group of three.
Worked example: encoding a 4-bit message
Original message: 1 0 1 1
Encoded (repeat each bit 3 times): 111 000 111 111
Transmitted: 12 bits total for 4 bits of data.
Case 1 — one error occurs:
Received: 101 000 111 111
(first group has a flipped bit)
Majority vote on each group: 1 0 1 1 — original recovered correctly.
Case 2 — two errors in the same group:
Received: 001 000 111 111
(two bits flipped in the first group)
Majority vote: 0 0 1 1 — wrong! The decoder is fooled.
Repetition-3 can only correct single-bit errors per group.
The Cost of Redundancy
The code rate R = k/n, where k is the number of data bits and n is the total number of transmitted bits. Repetition-3 has a rate of 1/3 — we send 3 bits for every 1 bit of actual data. That is a 200% overhead.
Can we do better? Yes. Hamming codes achieve a rate of 4/7 (about 0.57) while still correcting any single-bit error. We will get there by the end of this series, but first we need to understand parity.
Single Parity Bit
Instead of tripling every bit, what if we add just one extra bit to a block of data? The parity bit is chosen so that the total number of 1s in the block (data + parity) is even. This is called even parity.
Encoding
- Start with the data bits:
1 0 1 1 0 0 1(7 bits). - Count the 1s: there are four 1s. Four is even.
- Set the parity bit to
0(the count is already even). - Transmit:
1 0 1 1 0 0 1 0(8 bits).
Checking (no error)
- Receive:
1 0 1 1 0 0 1 0. - Count all 1s including the parity bit: four. Even. No error detected.
Checking (single-bit error)
- Receive:
1 0 1 0 0 0 1 0(bit 4 flipped from 1 to 0). - Count all 1s: three. Odd. Error detected!
With even parity, any single-bit flip changes the count from even to odd, and the check catches it. The rate is 7/8 — far better than repetition's 1/3.
What Parity Can and Can't Do
Detects
- Any single-bit error
- Any odd number of bit errors (3, 5, 7, ...)
- Cheaply — only 1 extra bit per block
Misses
- Two-bit errors (even count is preserved)
- Any even number of bit errors
- Cannot correct — it knows something is wrong but not which bit flipped
Single parity is a detection-only scheme. It tells you the message is damaged but gives you no way to repair it. To fix errors, we need more structure.
Two-Dimensional Parity
Here is a clever extension: arrange your data bits in a grid and compute parity for each row and each column. If a single bit flips, exactly one row parity and one column parity will fail — and their intersection pinpoints the bad bit.
Original 4×4 data grid with row and column parities:
C1 C2 C3 C4 | Row P
R1: 1 0 1 1 | 1
R2: 0 1 0 0 | 1
R3: 1 1 1 0 | 1
R4: 0 0 1 1 | 0
-----------------+----
Col P: 0 0 1 0 | 1 ← corner parity
Each row parity makes its row's total count of 1s even. Same for each column.
Now flip one bit — R2,C2 changes from 1 to 0:
C1 C2 C3 C4 | Row P Check
R1: 1 0 1 1 | 1 even OK
R2: 0 [0] 0 0 | 1 odd FAIL
R3: 1 1 1 0 | 1 even OK
R4: 0 0 1 1 | 0 even OK
-----------------+----
Col P: 0 0 1 0 | 1
Check: even odd even even
OK FAIL OK OK
Row 2 fails. Column 2 fails. The intersection is R2, C2 — flip that bit back to correct the error. Two-dimensional parity can correct any single-bit error in the grid.
Parity in Practice
Parity is not just a textbook concept. It appears throughout real systems:
| System | How Parity Is Used |
|---|---|
| RAM (parity memory) | 1 parity bit per 8 data bits; detects single-bit errors in memory reads |
| Serial communication (UART) | Optional parity bit per byte; detects transmission errors on the wire |
| ISBN check digit | Weighted sum mod 11; catches single-digit errors and transpositions in book numbers |
| Luhn algorithm | Check digit on credit card numbers; detects accidental typos |
| RAID (levels 3, 4, 5) | XOR parity across disk drives; reconstructs a failed drive's data from the others |
From Detection to Correction
Detection tells you an error exists. Correction tells you where it is. The more redundancy you add, the more errors you can handle, but you pay in bandwidth or storage.
The fundamental question is: what is the minimum redundancy needed to correct t errors in a block of k data bits? Richard Hamming answered this in 1950 with an elegant construction that uses parity bits placed at power-of-two positions. We will build Hamming codes from scratch later in this series.
Key Takeaways
- Errors are inevitable in any real communication or storage system.
- Repetition codes work but are wasteful — a rate of 1/3 means 200% overhead.
- A single parity bit detects any odd number of errors at a cost of just one extra bit per block.
- Parity alone cannot correct errors — it only signals that something went wrong.
- Two-dimensional parity can locate and correct a single-bit error by intersecting the failing row and column.
- The code rate R = k/n measures the efficiency of an error-correcting code. Higher is better, but more correction power requires more redundancy.
Try It Yourself — Parity Bit Calculator
Enter a sequence of data bits below to see how a parity bit is computed, appended, and verified.
Try It Yourself — 2D Parity Grid
Click any data cell to flip its value (simulating a bit error). The failing row and column parity cells highlight red, pinpointing the corrupted bit.
Parity gives us detection. Two-dimensional parity gives us correction for single errors. But real-world data faces burst errors — whole sequences of bits corrupted at once — and we need schemes that catch those reliably. In the next page, we look at checksums and cyclic redundancy checks (CRC), which treat entire blocks of data as numbers and use arithmetic to catch a much wider range of errors.