2.2 Error Detection: Parity, Checksum & Cyclic Redundancy Check (CRC)
💡 Core Intuition: The Check Digit Principle
🍳 The Everyday Analogy: The Barcode Check Digit & Bank Check Sums
Whenever you purchase an item at a supermarket, the cashier scans a barcode with an optical laser. The final digit on that barcode is not part of the manufacturer's item code—it is a mathematical check digit:
- If the laser lens is smudged or the cashier mistypes a digit on the keypad, the checkout scanner instantly beeps with an error.
- The scanner does not know what the correct number was; it simply knows that the mathematical relationship between the digits was violated.
Similarly, bank checks encode account routing numbers using checksum algorithms. If a single digit is transposed, the automated clearinghouse rejects the transaction immediately.
💻 Bridging to Computer Science
In computer networks, physical transmission media (copper wires, fiber strands, atmospheric radio frequencies) are continuously bombarded by electromagnetic interference, thermal noise, and signal attenuation. These physical phenomena flip transmitted s into s and s into s.
To protect data integrity, the sender calculates a mathematical signature from the payload and appends these redundant bits to the frame. The receiver recomputes the calculation upon arrival. If the signatures do not match, the frame is corrupted.
📑Table of Contents
- ⚡ Error Types in Physical Transmission
- 🧱 The Redundancy Principle & Block Coding
- 📏 Hamming Distance & Error Detection Theorems
- ⚖️ Detection Techniques: Parity, Checksum & CRC
- 🔢 1. Single Parity Check (1D Parity)
- 🔲 2. Two-Dimensional Parity Check (2D Parity)
- 🌐 3. The Internet Checksum (1's Complement Arithmetic)
- ⚙️ 4. Cyclic Redundancy Check (CRC)
- 🔄 Interactive Flagship Pipeline: CRC Generation & Syndrome Verification
- 🛡️ Error Detection Theorems of Generator Polynomial G(x)
- 🏭 Real-World Production Context
- 📐 Numerical Applications & Worked Examples
- 🎯 Exam & Interview Pitfall Check
⚡ Error Types in Physical Transmission
When electromagnetic noise strikes a physical transmission medium, it perturbs the electrical voltage, optical pulse, or radio wave.
Why Burst Errors Dominate Modern Networks
The physical duration of an electromagnetic noise pulse (such as an electrical motor spark or lightning impulse lasting ) is vastly longer than the duration of an individual bit on a high-speed transmission link:
- On a Ethernet link, a single bit lasts only ().
- A tiny noise spike of () wipes out consecutive bits!
- Consequently, modern data link layer error detection mechanisms must be optimized specifically to trap burst errors.
🧱 The Redundancy Principle & Block Coding
To detect or correct errors, we cannot simply rely on raw information bits. We must introduce Redundancy: extra bits appended solely to verify transmission fidelity.
In Block Coding, we partition our message into -bit chunks called Datawords. We then transform each -bit dataword into an -bit Codeword by appending redundant bits:
Block Coding Codeword Mapping Pipeline
Mapping k-bit datawords into a sparse subset of 2^n valid codewords
2^k Datawords (k bits)
Original application payload chunks of length k.
2^k Valid Patterns
Encoded n-bit words separated by minimum distance d_min.
2^n - 2^k Error Space
Corrupted words falling here trigger instant error alarms.
- Valid vs. Invalid Codewords: Out of the possible patterns of length , only represent valid codewords. The remaining combinations are strictly invalid.
- Detection Mechanism: If channel noise corrupts a valid codeword into an invalid codeword, the receiver detects the error immediately. If noise happens to corrupt a valid codeword into another valid codeword, the error slips through undetected.
📏 Hamming Distance & Error Detection Theorems
The Hamming Distance between two binary words of equal length is the number of bit positions in which the corresponding bits differ:
- Example: For and :
Minimum Hamming Distance ()
The Minimum Hamming Distance of a block code is the smallest Hamming distance between any pair of valid codewords in the code:
🛡️ Theorem 1: Condition for Error Detection
To guarantee the detection of up to bit errors across any transmitted codeword, the minimum Hamming distance of the code must satisfy:
- Intuition: If the transmitter sends valid codeword and bits are flipped, the corrupted pattern is at distance from . If every other valid codeword is at least distance away, the corrupted pattern can never match any other valid codeword, guaranteeing detection!
🔧 Theorem 2: Condition for Error Correction
To guarantee the forward correction of up to bit errors without retransmission, the minimum Hamming distance must satisfy:
- Intuition: If at most bits flip, the received pattern remains strictly closer to the original valid codeword (distance ) than to any other valid codeword (distance ). The receiver selects the nearest valid codeword via majority decoding.
⚖️ Detection Techniques: Parity, Checksum & CRC
🔢 1. Single Parity Check (1D Parity)
In a simple parity-check code:
- For a -bit dataword, redundant parity bit is appended ().
- Even Parity: Parity bit is chosen such that the total number of s in the codeword is even.
- Odd Parity: Parity bit is chosen such that the total number of s in the codeword is odd.
- Mathematical Limitation: .
- Since .
- It can reliably detect only 1 single-bit error (or any odd number of errors).
- If noise flips two bits simultaneously (e.g., and ), the total count of s remains even, completely blinding the receiver!
🔲 2. Two-Dimensional Parity Check (2D Parity)
To overcome the limitations of simple parity, data is organized into a two-dimensional grid of rows and columns:
- An even parity bit is computed for each row (horizontal parity).
- An even parity bit is computed for each column (vertical parity).
- The intersection of an erroneous row and erroneous column pinpoints the exact bit that flipped, enabling single-bit error correction!
| Data Matrix | Bit 1 | Bit 2 | Bit 3 | Bit 4 | Bit 5 | Bit 6 | Row Parity |
|---|---|---|---|---|---|---|---|
| Row 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 |
| Row 2 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
| Row 3 | 0 | 1 | 1 | 1 | 0 | 0 | 1 |
| Row 4 | 0 | 1 | 0 | 1 | 1 | 1 | 0 |
| Column Parity | 0 | 1 | 0 | 0 | 1 | 0 | 0 (Corner) |
- Capabilities:
- Detects all -bit, -bit, and -bit errors.
- Detects most burst errors within the block.
- Corrects any single-bit error by locating .
- Failure Case: Fails if an even number of bits flip in both the same row and the same column (a 4-bit rectangular error pattern).
🌐 3. The Internet Checksum (1's Complement Arithmetic)
Employed by the Internet Protocol suite (IPv4, TCP, UDP), the Checksum uses one's complement addition:
Sender Algorithm
- The message is divided into -bit words.
- All -bit words are summed using 1's complement addition:
- Any carry bit generated beyond the 16th bit is wrapped around and added back to the lowest bit (End-Around Carry).
- The final sum is inverted bitwise (one's complemented) to produce the Checksum.
- The Checksum is appended to the packet.
Receiver Algorithm
- The receiver sums all incoming -bit words plus the received Checksum using 1's complement addition.
- If the transmission is error-free, the resulting sum must be all 1s (
0xFFFF) (or equivalently, its one's complement must be all 0s (0x0000)). - Any other result indicates corruption the packet is discarded.
⚙️ 4. Cyclic Redundancy Check (CRC)
The Cyclic Redundancy Check (CRC) is the undisputed cornerstone of modern Data Link Layer error detection (Ethernet IEEE 802.3, Wi-Fi 802.11, HDLC, USB, and SATA).
The Mathematical Framework: Polynomial Arithmetic in
A binary string is expressed as an algebraic polynomial with coefficients in the Galois Field of order 2 (), where coefficients are strictly or :
- Modulo-2 Arithmetic Rules:
- Binary addition and subtraction are identical and equivalent to bitwise XOR ().
- Zero Carries and Zero Borrows:
CRC Mathematical Transformation Stages
Augmenting payload with zeros, dividing by G(x), and replacing with remainder
Dataword D(x)
k-bit binary dataword representation.
Augmented D(x) · 2^r
Appends r zeros clearing space for CRC remainder.
Remainder R(x)
r-bit remainder resulting from polynomial division.
Transmitted Codeword T(x)
Self-checking codeword divisible by G(x) with 0 remainder.
The Step-by-Step CRC Algorithm
- Determine Divisor Length: Let the generator polynomial have degree . The binary divisor has bits.
- Append Zeros: Append zeros to the right of the -bit dataword (equivalent to multiplying by ).
- Modulo-2 Division: Perform binary XOR long division of the augmented dataword by the divisor .
- Extract Remainder: The division yields a remainder of length bits.
- Form Codeword: Replace the appended zeros with the remainder bits . Transmit the -bit codeword .
- Receiver Verification: The receiver divides the received codeword by .
- If Remainder = 0: The frame is accepted as valid (zero syndrome).
- If Remainder 0: An error occurred; frame is dropped!
🔄 Interactive Flagship Pipeline: CRC Generation & Syndrome Verification
The pipeline below details the end-to-end mathematical lifecycle of CRC: appending zeros, running modulo-2 XOR division, transmitting the framed codeword, and running the receiver syndrome checker.
Cyclic Redundancy Check (CRC): End-to-End Modulo-2 Division Pipeline
Interactive state sequence tracing dataword augmentation, XOR polynomial division, channel transmission, and syndrome checking
🛡️ Error Detection Theorems of Generator Polynomial
The error-detecting power of CRC is determined entirely by the mathematical properties of the chosen generator polynomial :
| Error Category | Condition on Generator Polynomial | Detection Guarantee |
|---|---|---|
| All Single-Bit Errors | has terms and the term is non-zero () | Guaranteed |
| All Double-Bit Errors | does not divide for any max frame length | Guaranteed |
| All Odd Numbers of Errors | contains as a factor | Guaranteed |
| Burst Errors of Length | Generator degree is | Guaranteed |
| Burst Errors of Length | Generator degree is | ( for CRC-16) |
| Burst Errors of Length | Generator degree is | ( for CRC-32) |
Industry Standard Polynomials
- CRC-8: (ATM headers)
- CRC-16: (Modbus, USB)
- CRC-CCITT: (HDLC, X.25, Bluetooth)
- CRC-32: (Ethernet 802.3, Wi-Fi 802.11, ZIP, PNG)
🏭 Real-World Production Context
How Ethernet NICs Compute CRC-32 at 100 Gbps Speeds
In production network interface cards (NICs) and core routers, computing CRC-32 by sequentially looping through bits in software would choke CPU performance:
- Hardware implementations deploy Linear Feedback Shift Registers (LFSR) directly in silicon.
- Modern 100GbE NICs utilize parallelized Galois matrix multipliers capable of ingesting 64 bytes per clock cycle.
- The Frame Check Sequence (FCS) trailer appended to every Ethernet frame is validated on-the-fly as bits stream through the physical transceiver, dropping damaged frames before they consume a single cycle of host CPU memory bandwidth.
📐 Numerical Applications & Worked Examples
Example 1: Full CRC Polynomial Division & Codeword Generation
Problem Statement:
The message 11001001 is to be transmitted using the CRC generator polynomial . Calculate:
- The CRC redundancy bits (remainder).
- The complete transmitted codeword.
Step-by-Step Solution:
- Convert Generator Polynomial to Binary:
- Degree of polynomial . The binary divisor has bits.
- Augment the Dataword with Zeros:
- Execute Modulo-2 XOR Long Division:
- Step 1: Leading 4 bits
11001001=0101. Bring down11011. - Step 2:
10111001=0010. Bring down00100. Bring down01001. - Step 3:
10011001=0000. Bring down00000. Bring down00000. - Step 4: After bringing down all augmented zeros, the resulting 3-bit remainder is:
- Step 1: Leading 4 bits
- Construct the Transmitted Codeword:
- Final Result:
- The CRC check bits are
011. - The transmitted codeword is
11001001011.
- The CRC check bits are
Example 2: Frame Length Determination with High-Degree Polynomials
Problem Statement:
A transmitter sends a 10-bit payload message . The system protects frames using the CRC generator polynomial . Determine the total number of bits in the transmitted codeword frame.
Step-by-Step Solution:
- Identify Given Parameters:
- Message length .
- Generator polynomial: .
- Determine Generator Degree ():
- The highest exponent in is .
- A generator of degree produces a remainder of exactly bits.
- Calculate Codeword Length ():
- Final Result: The transmitted message frame spans exactly .
Example 3: Error Detection & Correction Guarantees from Minimum Hamming Distance
Problem Statement:
A block coding scheme is designed with a minimum Hamming distance . Determine:
- The maximum number of bit errors the code is guaranteed to detect.
- The maximum number of bit errors the code is guaranteed to correct.
Step-by-Step Solution:
- Error Detection Guarantee ():
- The code is mathematically guaranteed to detect up to bit errors.
- Error Correction Guarantee ():
- Since must be an integer, .
- The code is guaranteed to forward-correct up to bit error.
🎯 Exam & Interview Pitfall Check
Question 1: "Why can a simple parity bit detect only odd numbers of errors but never even numbers?"
Key Focus Points:
- In even parity, the parity bit guarantees an even total count of 1s.
- A single bit flip changes the parity from even to odd (detected).
- A second bit flip changes the parity back from odd to even! Thus, any even number of bit inversions restores the expected parity status, rendering the receiver blind to the corruption.
Question 2: "What is the significance of the term being non-zero in a CRC generator polynomial?"
Key Focus Points:
- The term corresponds to the constant .
- If , has as a common factor ().
- A generator with a factor of cannot detect a single-bit error that shifts the bitstream or occurs in the least significant bit, violating the fundamental theorem for single-bit error detection!
Question 3: "How does CRC achieve line-rate hardware speeds in network switches?"
Key Focus Points:
- Modulo-2 division requires no multiplication, carries, or borrows.
- In hardware, CRC is implemented using a Linear Feedback Shift Register (LFSR) consisting of flip-flops and XOR gates corresponding to the generator polynomial coefficients. Bits are clocked through at 1 bit per clock cycle with zero ALU latency!
Trap 1: "Can CRC perform error correction?"
Answer: Mathematically yes, but practically no in standard protocols. While cyclic codes can technically correct errors using algebraic syndrome decoding (e.g., BCH and Reed-Solomon codes), standard Data Link Layer protocols (Ethernet, Wi-Fi) use CRC strictly for error detection. When an error is detected, the frame is simply discarded, and the link layer relies on Automatic Repeat Request (ARQ) retransmissions.
Trap 2: "Is the Internet Checksum stronger than CRC?"
Answer: Absolutely NOT. The Internet Checksum is based on simple 1's complement addition. It is vulnerable to compensating errors—for instance, if one bit changes from to in word and another changes from to in word , the sum remains unchanged! CRC uses non-linear polynomial modulo-2 arithmetic and is orders of magnitude stronger at detecting burst errors. The Internet Checksum was chosen solely for its software speed on 1980s CPUs.