Cyclic Redundancy Check
Cyclic Redundancy Check (CRC)
The error-detection technique widely used in today's computer networks is based on cyclic redundancy check. CRC codes are also called polynomial codes.
CRC calculations use mod-2 arithmetic: addition has no carries and subtraction has no borrows. This means addition and subtraction are identical, and mod-2 arithmetic is equivalent to the exclusive-or (XOR) operation.
KNOWLEDGE QUIZ
Sender and Receiver
Suppose the data to send is bits long. The sender and receiver must first agree on an -bit generator polynomial .
The sender appends an -bit value R to the data , obtaining a sequence of bits that is exactly divisible by in mod-2 arithmetic.
The receiver divides the bits it receives by . If the remainder is not 0, an error has occurred.
The -bit sequence the sender needs can be built by shifting left by bits and adding . Since the resulting -bit sequence is divisible by , it is an integer multiple of :
is the remainder of divided by :
A Worked Example
Suppose = 101110 and = 1001. Then = 3, so three 0s are appended to before dividing.
The remainder is 011, so the sender transmits 101110011.
Step through CRC mod-2 long division
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
Why "Polynomial Code"?
A bit string can be viewed as a polynomial whose coefficients are 0 or 1, with the leftmost bit as the highest power. For example, corresponds to , and to . Shifting left by bits multiplies by , and mod-2 long division is polynomial division in which coefficients are added and subtracted with XOR.
Which Errors Does CRC Detect?
Let be the transmitted bits and let the error pattern have a 1 at every corrupted position, so the receiver gets . Because is a multiple of :
So an error goes undetected only when happens to be a multiple of . This gives CRC several important properties:
| Error type | Detected? | Reason |
|---|---|---|
| Single-bit error | Always | The first and last bits of are 1, so is never a multiple of |
| Burst of length at most | Always | A non-zero polynomial of lower degree than cannot be a multiple of |
| Odd number of bit errors | Always, if has the factor | Every multiple of has an even number of 1s |
| Random errors | Missed with probability about | Only multiples of slip through |
The CRC-32 used by Ethernet and 802.11 has , so random errors slip through with probability about , and every burst of length at most 32 is detected. CRC can be computed at high speed in hardware with shift registers and XOR gates, which is one reason it is so widely used.
Corrupt a CRC frame and see what the remainder catches
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Compute and check a CRC by hand
The data is D = 110101 and the generator is G = 101.
- Compute the CRC bits R and the 8 bits the sender transmits.
- The receiver gets 11000111. Is the error detected?
- The receiver gets 11111111. Which bits are wrong, and what does the receiver decide? Explain.
Implement CRC in Python and compare two generators
Write Python functions mod2_remainder(bits, gen) and crc_encode(data, gen) that work on strings of 0s and 1s. Use them to (1) reproduce this section's example D = 101110, G = 1001 and check the frame at the receiver; (2) show that flipping one bit gives a non-zero remainder; (3) count how many of the 36 possible double-bit errors in the 9-bit frame go undetected with G = 1001 and with G = 1011.