Error detection: parity, checksum and CRC
How a receiver notices that bits were flipped in transit: single parity, two-dimensional parity, the Internet (ones' complement) checksum and the cyclic redundancy check; CRC by modulo-2 long division with every step, the generator polynomial, what a CRC provably detects (all single-bit errors, bursts up to the CRC length, odd numbers of errors when x + 1 divides the generator) and how many error patterns escape; the divisions were checked against zlib's CRC-32 and the detection claims by trying every error pattern.
Why it exists
Noise flips bits. The data link layer therefore adds redundancy to each frame so the receiver can detect (and then discard, or ask for a repeat) damaged frames. The redundancy is a few bits computed from the data; the receiver recomputes and compares. Methods differ in cost and in which errors they catch. (Methods that also locate the wrong bit are error-correcting codes, as in the Hamming code, and cost more bits.)
Prerequisites
You need the idea that the link layer builds frames (layering). No algebra beyond modulo-2 arithmetic is used.
Precise definitions
Error types. A single-bit error flips one bit. A burst error of length is a pattern whose first and last wrong bits are positions apart (the bits between may or may not be wrong). The Hamming distance between two bit strings is the number of positions in which they differ; a code in which every two codewords differ in at least positions detects every pattern of fewer than bit errors.
Parity. Even parity: append one bit so the number of ones is even. Detects every odd number of bit errors, misses every even number.
Two-dimensional parity. Arrange the data in rows, append a parity bit to each row and a parity row for the columns.
Internet checksum (used by IP, TCP, UDP): divide the data into -bit words, add them in ones' complement arithmetic (a carry out of the top is added back at the bottom), and send the complement of the sum. The receiver adds all words including the checksum; the result must be all ones.
CRC (cyclic redundancy check). Choose a generator of bits, written as a polynomial over the field with two elements (for example , ). To send a data word :
- append zeros to (this is );
- divide by the generator using modulo-2 arithmetic (subtraction is XOR, no borrows); the remainder has bits;
- send followed by the remainder: the codeword, which is exactly divisible by the generator.
The receiver divides the received bits by the generator: remainder means "no error detected".
An error pattern (a polynomial with ones where bits flipped) goes undetected exactly when the generator divides : the received word is codeword .
How it works
Long division step by step
CRC by long division: data 1101011011, generator 10011 (x^4 + x + 1): start
Computed by a script, not typed| step | window | XOR with generator | result |
|---|---|---|---|
| step 1 (position 0) | |||
| step 2 (position 1) | |||
| step 3 (position 6) | |||
| step 4 (position 8) | |||
| remainder |
Step 0
Dividend: the data with 4 zeros appended: 11010110110000. Modulo-2 arithmetic: subtraction is XOR, no borrows.
Data , generator (, ). Write the data with four zeros appended: . Whenever the leftmost bit of the current window is , XOR the generator into the window; otherwise slide. The four XOR steps leave the remainder . The frame sent is . Dividing it by gives remainder .
What a CRC detects
A generator with a nonzero constant term (a in the last place) and at least two terms:
- detects all single-bit errors (the pattern is never a multiple of such a generator);
- detects all burst errors of length at most (a pattern with ones only within consecutive positions has degree less than after removing the trailing zeros, so a multiple of the generator of degree cannot fit);
- detects all odd numbers of bit errors if divides the generator, which happens exactly when the generator has an even number of terms (an even number of ones);
- detects every double-bit error if the frame is shorter than the order of modulo the generator (for the order is , for it is ).
The number of error patterns that escape is exactly the number of non-zero multiples of the generator that fit in the frame: for an -bit frame.
What a CRC detects (all error patterns tried): start
Computed by a script, not typed| generator and frame length | undetected patterns | formula | all single-bit errors detected | undetected 2-bit patterns | divisible by x + 1 | all bursts of length at most r detected |
|---|---|---|---|---|---|---|
| 1011 (x^3 + x + 1), frame 7 bits | ||||||
| 1011 (x^3 + x + 1), frame 8 bits | ||||||
| 10011 (x^4 + x + 1), frame 15 bits | ||||||
| 1001 (x^3 + 1), frame 7 bits |
Step 0
Every one of the 2^n - 1 non-zero error patterns is divided by the generator. A pattern is undetected exactly when the generator divides it.
For and bits: of the error patterns exactly are undetected, and none of them has one or two flipped bits. At bits one double error escapes (positions apart). The generator has two terms, so divides it: odd-weight errors cannot escape, but five double-bit patterns do. Real protocols use generators of degree or (Ethernet uses the CRC-32 polynomial, quoted, and checked here against the standard library implementation).
The other methods on the same errors
Parity misses all even numbers of errors, including two flipped bits. Two-dimensional parity on a block:
Two-dimensional parity: which errors are missed (all patterns tried): start
Computed by a script, not typed| number of flipped bits | patterns | undetected | result |
|---|---|---|---|
| 1 bit error | |||
| 2 bit errors | |||
| 3 bit errors | |||
| 4 bit errors | |||
| 5 bit errors |
Step 0
Block: rows 1011, 0110, 1100 with an even-parity bit per row and a parity row for the columns (20 bits in total).
All patterns of , and flipped bits are detected, and a single flipped bit can even be located (the wrong row and the wrong column) and corrected. Four flipped bits at the corners of a rectangle change each affected row and column parity twice and are missed: of the patterns.
The Internet checksum:
Internet checksum of 10 words (the words of a sample IPv4 header, checksum field taken as 0000): start
Computed by a script, not typed| step | word | running sum | note |
|---|---|---|---|
| add 4500 | |||
| add 0073 | |||
| add 0000 | |||
| add 4000 | |||
| add 4011 | |||
| add 0000 | |||
| add C0A8 | |||
| add 0001 | |||
| add C0A8 | |||
| add 00C7 | |||
| checksum |
Step 0
The 16-bit words are the first ten words of a sample header; the checksum field is zero while computing. Ones' complement addition: carries wrap around.
The ten words are the words of a sample IPv4 header (checksum field set to zero). The sum is , the checksum (the complement), and the receiver's sum of all eleven words is . The checksum is cheap to compute in software but weaker than a CRC: it cannot detect two words swapped, or errors in different words that compensate, and its sum is the same if words are reordered.
| method | extra bits | catches | misses |
|---|---|---|---|
| single parity | every odd number of errors | every even number | |
| 2D parity | one per row and column | all errors of 1, 2, 3 bits | rectangles of 4 |
| Internet checksum | most single and burst errors | reordered words, compensating errors | |
| CRC (degree ) | all single, all bursts , possibly all odd | a fraction of random errors (textbook value) |
Worked examples
EX 1Even parity
EasyData has four ones; the even-parity bit is . Data has three ones; the bit is . The received word has five ones (odd): an error is detected, but its position is unknown.
EX 2CRC by hand
MediumData , generator : remainder (table above). Transmitted: . If the receiver gets (last bit flipped) the remainder is , non-zero: the error is detected (a single-bit error never escapes).
EX 3Which generator
MediumGenerator (): has two terms, so it is divisible by ; every odd number of errors is detected. Generator has three terms: not divisible by , odd-weight errors can escape. Both detect all single errors and all bursts of length at most .
EX 4Typical questions
GATE level(a) "Number of bits appended by a CRC with generator ?" (the degree). (b) "Maximum burst length always detected by a CRC of check bits?" . (c) "Does CRC detect every error pattern of 2 bits?" Only if the frame is shorter than the order of modulo the generator (for : frames up to bits). (d) "Size of the Internet checksum?" bits. (e) "Which scheme can correct single-bit errors: parity, 2D parity, CRC?" Two-dimensional parity can locate one wrong bit; one-dimensional parity and CRC only detect.
Cheat box
Cheat box
- Even parity: odd errors detected. 2D parity: all up to 3 errors, corrects 1.
- Checksum: 16-bit ones' complement sum, send the complement; receiver sum must be all ones.
- CRC: append zeros, divide modulo 2, send data + remainder; receiver divides, remainder is OK.
- CRC detects all single errors, all bursts , all odd errors if divides ; misses patterns that are multiples of : of them in an -bit frame.
- Subtraction in modulo-2 arithmetic is XOR.
Traps and GATE patterns
Connections
Builds on
Unlocks
Across subjects
No cross-subject links yet.
Ethernet frames end with a -bit CRC (Ethernet); the IPv4 header has a checksum that routers recompute (IPv4 fragmentation and the header). Detecting an error leads to retransmission, handled by the sliding window protocols (sliding window); error-correcting codes avoid retransmission at the cost of more bits (Hamming code).
PYQs
4 previous year questions from your book. I re-solved each one myself (4 by running or simulating, 0 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the cyclic redundancy check (CRC) based error detecting scheme having the generator polynomial x3+x+1. Suppose the message m4m3m2m1m0=11000 is to be transmitted. Check bits c2c1c0 are appended at the end of the message by the transmitter using the above CRC scheme. The transmitted bit string is denoted by m4m3m2m1m0c2c1c0. The value of the check bit sequence c2c1c0 is:
- (a)110
- (b)111
- (c)100
- (d)101
A computer network uses polynomials over GF(2) for error checking with 8 bits as information bits and uses x3+x+1 as the generator polynomial to generate the check bits. In this network, the message 01011011 is transmitted as:
- (a)01011011010
- (b)01011011011
- (c)01011011101
- (d)01011011100
Let G(x) be the generator polynomial used for CRC checking. What is the condition that should be satisfied by G(x) to detect odd number of bits in error?
- (a)G(x) contains more than two terms
- (b)G(x) does not divide 1 + xk, for any k not exceeding the frame length
- (c)1 + x is a factor of G(x)
- (d)G(x) has an odd number of terms.
The message 11001001 is to be transmitted using the CRC polynomial x3 + 1 to protect it from errors. The message that should be transmitted is:
- (a)11001001000
- (b)11001001011
- (c)11001010
- (d)110010010011 COMPUTER NETWORK
Self-check
Question 1
Compute the CRC for data with generator .
Show answerHide
Append three zeros: . Divide by : , bring down: the window sequence gives remainder . The frame is .
Question 2
Can a CRC with generator miss an error pattern with three flipped bits?
Show answerHide
No: is divisible by (two terms, an even number), so every odd-weight pattern is detected.
Question 3
Why does two-dimensional parity miss four errors at the corners of a rectangle?
Show answerHide
Each of the two affected rows and two affected columns gets two flips, so every parity still looks right.
Revision card
One-screen revision
- Parity: odd errors. 2D parity: locate 1 error. Checksum: 16-bit ones' complement.
- CRC: appended; undetected iff divides the error pattern.
- Detects all single bits, bursts , odd errors if .
References
- ·Kurose, Ross, Computer Networking: A Top-Down Approach (8th edition), Chapter 6, Section 6.2 (Error-detection and -correction techniques)
- ·Tanenbaum, Wetherall, Computer Networks (5th edition), Chapter 3, Section 3.2 (Error detection and correction)
- ·Forouzan, Data Communications and Networking (5th edition), Chapter 10 (Error detection and correction)
Verification
scripts/enum-checks/cn_basic_check.py: (1) the long division of scripts/cn_lib.py equals carry-less polynomial remainder arithmetic on 2000 random data/generator pairs, every codeword is divisible by the generator, and the parametrised CRC reproduces zlib.crc32 and binascii.crc_hqx on random byte strings (so the algebra is the one used by real CRCs); (2) for six generators and frame lengths from r + 1 up to 16 bits, ALL 2^n - 1 non-zero error patterns were tested: the undetected ones are exactly the non-zero multiples of the generator, their number is 2^(n-r) - 1, no single-bit error and no burst of length at most r escapes, no odd-weight error escapes when x + 1 divides the generator, and a double error at distance k escapes exactly when k is a multiple of the order of x modulo the generator; (3) the Internet checksum is verified by adding the received checksum (result all ones), detects every single-bit error on 500 random messages and cannot see reordered words; the worked example reproduces the checksum B861 of a well-known sample header (computed here, not copied); (4) two-dimensional parity: all 1-, 2- and 3-bit errors on a 4 x 5 block are detected, and four errors at the corners of a rectangle are not (60 such patterns in 4845). The statement that a burst longer than r escapes with probability 2^-r (or 2^-(r-1) for exactly r+1) is the textbook value and was not enumerated here: NEEDS VERIFICATION. The Ethernet CRC-32 polynomial is quoted (the zlib check confirms the algorithm for that polynomial). Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (CRC remainders, binomial tail, checksums); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)