G27
Self-checkedTier 1 9 min readcn.error-detection-crc

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 bb is a pattern whose first and last wrong bits are bb 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 dd positions detects every pattern of fewer than dd 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 1616-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 r+1r + 1 bits, written as a polynomial over the field with two elements (for example 1011=x3+x+11011 = x^3 + x + 1, r=3r = 3). To send a data word DD:

  1. append rr zeros to DD (this is D⋅xrD \cdot x^r);
  2. divide by the generator using modulo-2 arithmetic (subtraction is XOR, no borrows); the remainder has rr bits;
  3. send DD followed by the remainder: the codeword, which is exactly divisible by the generator.

The receiver divides the received bits by the generator: remainder 00 means "no error detected".

An error pattern EE (a polynomial with ones where bits flipped) goes undetected exactly when the generator divides EE: the received word is codeword +E+ E.

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
stepwindowXOR with generatorresult
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.

0 / 5
computed by script: exact arithmetic (fractions), CRC long division and exhaustive enumeration of error patterns. python3 scripts/gen-cn1-traces.py

Data 11010110111101011011, generator 1001110011 (x4+x+1x^4 + x + 1, r=4r = 4). Write the data with four zeros appended: 1101011011000011010110110000. Whenever the leftmost bit of the current window is 11, XOR the generator into the window; otherwise slide. The four XOR steps leave the remainder 11101110. The frame sent is 1101011011111011010110111110. Dividing it by 1001110011 gives remainder 00.

What a CRC detects

A generator with a nonzero constant term (a 11 in the last place) and at least two terms:

  • detects all single-bit errors (the pattern xix^i is never a multiple of such a generator);
  • detects all burst errors of length at most rr (a pattern with ones only within rr consecutive positions has degree less than rr after removing the trailing zeros, so a multiple of the generator of degree rr cannot fit);
  • detects all odd numbers of bit errors if (x+1)(x + 1) 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 xx modulo the generator (for x3+x+1x^3 + x + 1 the order is 77, for x4+x+1x^4 + x + 1 it is 1515).

The number of error patterns that escape is exactly the number of non-zero multiples of the generator that fit in the frame: 2n−r−12^{n-r} - 1 for an nn-bit frame.

What a CRC detects (all error patterns tried): start

Computed by a script, not typed
generator and frame lengthundetected patternsformulaall single-bit errors detectedundetected 2-bit patternsdivisible by x + 1all 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.

0 / 4
computed by script: exact arithmetic (fractions), CRC long division and exhaustive enumeration of error patterns. python3 scripts/gen-cn1-traces.py

For 10111011 and 77 bits: of the 127127 error patterns exactly 1515 are undetected, and none of them has one or two flipped bits. At 88 bits one double error escapes (positions 77 apart). The generator 1001=x3+11001 = x^3 + 1 has two terms, so x+1x + 1 divides it: odd-weight errors cannot escape, but five double-bit patterns do. Real protocols use generators of degree 1616 or 3232 (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 4×54 \times 5 block:

Two-dimensional parity: which errors are missed (all patterns tried): start

Computed by a script, not typed
number of flipped bitspatternsundetectedresult
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).

0 / 5
computed by script: exact arithmetic (fractions), CRC long division and exhaustive enumeration of error patterns. python3 scripts/gen-cn1-traces.py

All patterns of 11, 22 and 33 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: 6060 of the 48454845 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
stepwordrunning sumnote
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.

0 / 11
computed by script: exact arithmetic (fractions), CRC long division and exhaustive enumeration of error patterns. python3 scripts/gen-cn1-traces.py

The ten words are the words of a sample IPv4 header (checksum field set to zero). The sum is 479E479E, the checksum B861B861 (the complement), and the receiver's sum of all eleven words is FFFFFFFF. 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.

methodextra bitscatchesmisses
single parity11every odd number of errorsevery even number
2D parityone per row and columnall errors of 1, 2, 3 bitsrectangles of 4
Internet checksum1616most single and burst errorsreordered words, compensating errors
CRC (degree rr)rrall single, all bursts ≤r\le r, possibly all odda fraction 2−r2^{-r} of random errors (textbook value)

Worked examples

EX 1Even parity

Easy

Data 10110011011001 has four ones; the even-parity bit is 00. Data 10110001011000 has three ones; the bit is 11. The received word 1011010110110101 has five ones (odd): an error is detected, but its position is unknown.

EX 2CRC by hand

Medium

Data 11010110111101011011, generator 1001110011: remainder 11101110 (table above). Transmitted: 1101011011111011010110111110. If the receiver gets 1101011011111111010110111111 (last bit flipped) the remainder is 00010001, non-zero: the error is detected (a single-bit error never escapes).

EX 3Which generator

Medium

Generator 10011001 (x3+1x^3 + 1): has two terms, so it is divisible by x+1x + 1; every odd number of errors is detected. Generator 10111011 has three terms: not divisible by x+1x + 1, odd-weight errors can escape. Both detect all single errors and all bursts of length at most 33.

EX 4Typical questions

GATE level

(a) "Number of bits appended by a CRC with generator x4+x+1x^4 + x + 1?" 44 (the degree). (b) "Maximum burst length always detected by a CRC of rr check bits?" rr. (c) "Does CRC detect every error pattern of 2 bits?" Only if the frame is shorter than the order of xx modulo the generator (for x3+x+1x^3 + x + 1: frames up to 77 bits). (d) "Size of the Internet checksum?" 1616 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 rr zeros, divide modulo 2, send data + remainder; receiver divides, remainder 00 is OK.
  • CRC detects all single errors, all bursts ≤r\le r, all odd errors if x+1x + 1 divides GG; misses patterns that are multiples of GG: 2n−r−12^{n-r} - 1 of them in an nn-bit frame.
  • Subtraction in modulo-2 arithmetic is XOR.

Traps and GATE patterns

Connections

Ethernet frames end with a 3232-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

GATE 2021 · MCQ · 2 marksQ7 · page 534 of the book
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
GATE 2017 · MCQQ13 · page 535 of the book
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
GATE 2009 · MCQ · 2 marksQ33 · page 538 of the book
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.
GATE 2007 · MCQ · 2 marksQ35 · page 538 of the book
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 10011001 with generator 10111011.

Show answer

Append three zeros: 10010001001000. Divide by 10111011: 1001⊕1011=00101001 \oplus 1011 = 0010, bring down: the window sequence gives remainder 110110. The frame is 10011101001110.

Question 2

Can a CRC with generator x3+1x^3 + 1 miss an error pattern with three flipped bits?

Show answer

No: x3+1x^3 + 1 is divisible by x+1x + 1 (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 answer

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: D⋅xr mod GD \cdot x^r \bmod G appended; undetected iff GG divides the error pattern.
  • Detects all single bits, bursts ≤r\le r, odd errors if (x+1)∣G(x + 1) \mid G.

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