Introduction

The cyclic redundancy check is the error-detecting code used in the trailer of almost every link-layer frame: Ethernet's 32-bit frame check sequence (FCS) is a CRC, and so are the checks in Wi-Fi, HDLC and PPP. It treats the frame as a long binary polynomial, divides it by a fixed generator polynomial using arithmetic modulo 2, and sends the remainder. The receiver repeats the division over the whole received frame; a non-zero remainder means an error.

A CRC is preferred over parity and the Internet checksum because, for the same number of check bits, it catches far more error patterns, in particular all burst errors of length up to the number of check bits when the generator has a constant term, which is how errors on real links tend to look. It is also cheap in hardware: a shift register with a few XOR gates computes it at line rate.

Three tasks recur: compute the transmitted frame (do the division), decide whether a received frame is accepted, and decide which error patterns a given generator detects.

Prerequisites

Core concepts

Bit strings as polynomials

A bit string bk−1…b1b0b_{k-1} \ldots b_1 b_0 is the polynomial bk−1xk−1+⋯+b1x+b0b_{k-1}x^{k-1} + \cdots + b_1 x + b_0 with coefficients in {0,1}\{0, 1\}. For example 1011 is x3+x+1x^3 + x + 1 and 10011 is x4+x+1x^4 + x + 1. The degree is the highest power with coefficient 1.

TermMeaning
M(x)M(x)The message (data bits), mm bits
G(x)G(x)Generator, degree rr, so it is written with r+1r + 1 bits; both its highest and lowest bits are 1 in practice
R(x)R(x)Remainder, exactly rr bits (pad with leading zeros)
T(x)T(x)Transmitted frame: M(x)M(x) followed by R(x)R(x), m+rm + r bits
E(x)E(x)Error pattern: the bits that flipped; received frame is T(x)+E(x)T(x) + E(x)

Degree versus length. A generator of degree rr has r+1r + 1 bits and produces rr check bits. CRC-32 has a degree-32 generator (33 bits) and a 32-bit FCS.

Modulo-2 long division

At each step, if the leading bit of the current window is 1, XOR the generator into it (the quotient bit is 1); if it is 0, XOR zeros (the quotient bit is 0). Then move one position right. The last rr bits after the final step are the remainder. Only the remainder matters; the quotient is discarded.

A modulo-2 long division. Dividend 11010110 followed by three appended zeros, 11010110000, divided by 1011. Six XOR steps are shown under the dividend, each aligned with the leading 1 of the current remainder, at bit positions 1, 2, 3, 4, 6 and 8 counted from the left. Quotient 11110101 is written above. The final remainder 111 is boxed, and the transmitted frame 11010110111 is written below.
Figure 1. Dividing 11010110000 by the generator 1011 modulo 2: the quotient is 11110101 and the remainder 111 becomes the CRC, giving the frame 11010110111.

Algorithms and pseudocode

Bit strings are indexed from the left starting at 1; XOR acts bit by bit.

Text
CRC-REMAINDER(M, G)                 // M: m bits, G: r+1 bits with G[1] = 1
    r <- length(G) - 1
    A <- M followed by r zeros       // A[1 .. m+r]
    for i <- 1 to m
        if A[i] = 1 then
            for j <- 1 to r + 1
                A[i + j - 1] <- A[i + j - 1] XOR G[j]
    return A[m+1 .. m+r]             // the r-bit remainder

CRC-SEND(M, G)
    return M followed by CRC-REMAINDER(M, G)

CRC-CHECK(T, G)                      // T: received m+r bits
    divide T itself (no zeros appended) by G as above, for i <- 1 to m
    return (last r bits are all 0)

For the software shown (mm message bits, degree r≥1r\ge1 generator), copying/appending and storage cost Θ(m+r)\Theta(m+r). Best time is Θ(m+r)\Theta(m+r); worst time is O(mr+m+r)O(mr+m+r) bit operations, with average requiring a bit distribution. A table-driven version can process a byte per step. Streaming hardware instead uses an rr-bit shift register with feedback XORs, typically processing one input bit per clock; that is a different cost/storage model.

Mathematical explanation

Why the frame divides evenly. Appending rr zeros is multiplication by xrx^r. Write xrM(x)=Q(x)G(x)+R(x)x^r M(x) = Q(x)G(x) + R(x) with deg⁡R<r\deg R < r. Then

T(x)=xrM(x)+R(x)=Q(x)G(x)+R(x)+R(x)=Q(x)G(x),T(x) = x^r M(x) + R(x) = Q(x)G(x) + R(x) + R(x) = Q(x)G(x),

because R+R=0R + R = 0 modulo 2. So G(x)G(x) divides every correct frame.

When an error is missed. The receiver divides T(x)+E(x)T(x) + E(x); since G∣TG \mid T, the remainder is that of E(x)E(x) alone. An error is undetected exactly when G(x)G(x) divides E(x)E(x). Every undetected-error case follows from this.

Detection guarantees (for a generator of degree rr):

Error patternE(x)E(x)Detected when
Single bitxix^iGG has at least two terms (always true in practice)
Two bitsxi(xj−i+1)x^i(x^{j-i} + 1)GG has a constant term and does not divide xk+1x^k + 1 for any kk up to the frame length (for example, GG has a primitive factor of degree dd and the frame is shorter than 2d−12^d - 1 bits)
Any odd number of bitsE(1)=1E(1) = 1x+1x + 1 divides GG: then G(1)=0G(1) = 0, but E(1)=1E(1) = 1 for odd weight, so G∤EG \nmid E
Burst of length b≤rb \le rxiB(x)x^i B(x), deg⁡B=b−1<r\deg B = b - 1 < rGG has a constant term: then G∤xiG \nmid x^i and G∤BG \nmid B because deg⁡B<deg⁡G\deg B < \deg G
Burst of length r+1r + 1Missed only if B=GB = G: fraction 2−(r−1)2^{-(r-1)} of such bursts
Burst longer than r+1r + 1Missed with fraction 2−r2^{-r} of such patterns

Parity is the special case G(x)=x+1G(x) = x + 1. The remainder of xM(x)x M(x) divided by x+1x + 1 is M(1)M(1), the number of 1s in the message modulo 2: a one-bit CRC with generator 11 is an even parity bit.

Worked examples

Example 1: computing the CRC

Message 11010110, generator 1011 (x3+x+1x^3 + x + 1, r=3r = 3). Append three zeros: 11010110000. XOR 1011 under the leading 1 at positions 1, 2, 3, 4, 6 and 8 (Figure 1); the windows starting at positions 5 and 7 begin with 0, so their quotient bits are 0. Quotient 11110101, remainder 111. Transmitted frame: 11010110111.

Example 2: a degree-4 generator

Message 101101, generator 10011 (x4+x+1x^4 + x + 1). Append four zeros: 1011010000. The division, with the five-bit window under each leading 1:

StepLeading 1 at positionWindowAfter XOR with 10011Whole string afterwards
1110110001010010110000
2310110001010000101000
3510100001110000001110

Positions 2, 4 and 6 begin with 0, so the quotient is 101010. The remainder is the last four bits, 1110, and the frame is 1011011110.

Example 3: the receiver's view

The receiver of Example 1 divides 11010110111 by 1011 and gets remainder 000: accepted. If bit 5 flips (received 11011110111), the remainder is non-zero: rejected. If the error pattern is 00000101100, which is x2G(x)x^2 G(x), the received word 11010011011 leaves remainder 000 and the error is not detected: an error that is a multiple of the generator always escapes.

Example 4: what a generator guarantees

G(x)=x3+x+1G(x) = x^3 + x + 1 has a constant term and degree 3, so it catches every burst of length 3 or less. It is not divisible by x+1x + 1 (it has three terms, so G(1)=1G(1) = 1), so it does not catch every odd-weight error: the error pattern 1011 itself (weight 3) is missed. G(x)=(x+1)(x3+x+1)=x4+x3+x2+1G(x) = (x + 1)(x^3 + x + 1) = x^4 + x^3 + x^2 + 1 (11101) does catch all odd-weight errors and all bursts up to length 4.

Example 5: bursts and two-bit errors for 10011

G(x)=x4+x+1G(x) = x^4 + x + 1, so r=4r = 4. A burst of length b≥2b \ge 2 has its first and last bits set, so there are 2b−22^{b-2} patterns of each length.

Burst length bbPatternsUndetected
1 to 41, 1, 2, 40
581: 10011 itself
6161: 110101, which is (x+1)G(x)(x + 1)G(x)
7322

Shifting a burst multiplies it by xix^i, which does not change whether GG divides it, so these counts hold at every position in the frame. The undetected fractions are 1/8=2−(r−1)1/8 = 2^{-(r-1)} for b=r+1=5b = r + 1 = 5, and 1/16=2/32=2−r1/16 = 2/32 = 2^{-r} for the longer bursts, as in the table of detection guarantees.

A two-bit error xi(xj+1)x^i(x^j + 1) escapes exactly when GG divides xj+1x^j + 1. For this generator the smallest such jj is 15, so every two-bit error in a frame of at most 15 bits is caught, while two flipped bits exactly 15 positions apart escape. Because GG has three terms, G(1)=1G(1) = 1: x+1x + 1 is not a factor, and the weight-3 error 10011 escapes.

CRC-32 uses the degree-32 generator with hexadecimal coefficients 04C11DB7 (top bit implicit). Real implementations also preset the register to all ones, process each byte least significant bit first, and complement the result, so the FCS is not the plain remainder of the textbook division. The standard check value is: the CRC-32 of the nine ASCII bytes "123456789" is CBF43926.

Important properties and observations

  • The remainder always has exactly rr bits. Keep leading zeros: a remainder of 11 with r=3r = 3 is written 011.
  • The receiver does not append zeros. It divides the received m+rm + r bits directly.
  • Undetected means divisible. To find an undetected error, take any non-zero multiple of G(x)G(x) as the error pattern.
  • Linearity. The CRC of A⊕BA \oplus B equals CRC(AA) ⊕\oplus CRC(BB) for equal-length messages (plain division, no preset). This is why a table-driven implementation works.
  • CRC and the checksum. The CRC protects one link and every receiving interface tests it; TCP and UDP use the Internet checksum end to end; the IPv4 header checksum is hop by hop. A frame with a good CRC can still be corrupted inside a router's memory.

Common misconceptions.

  • "A degree-rr generator has rr bits." It has r+1r + 1 bits and produces rr check bits.
  • "Any generator catches all odd-weight errors." Only if x+1x + 1 is a factor.
  • "CRC can correct errors." A CRC is used only for detection in networking.

GATE examination perspective

  • Compute the frame. Append rr zeros, divide modulo 2, write the rr-bit remainder after the message. Check by dividing the frame: remainder zero.
  • Accept or reject. Divide the received frame without appending zeros.
  • Which errors are detected. Use the table: bursts ≤r\le r when GG has a constant term; odd weight if (x+1)∣G(x+1) \mid G; a pattern is missed exactly when it is a multiple of GG.
  • Bit counting traps. Degree versus number of bits; the number of check bits equals the degree.
  • Burst counting. For b≥2b\ge2, there are 2b−22^{b-2} burst patterns of length bb; for b=1b=1, there is one. For either case, the undetected ones are the multiples of GG of that length (Example 5).
  • Parity as CRC. Generator 11 gives one even parity bit.

Summary

Sources

  1. A. S. Tanenbaum, D. J. Wetherall, Computer Networks, 5th ed., Pearson, 2011: Section 3.2.2 (Error-Detecting Codes, including the CRC).
  2. J. F. Kurose, K. W. Ross, Computer Networking: A Top-Down Approach, 8th ed., Pearson, 2021: Section 6.2.3 (Cyclic Redundancy Check (CRC)).
  3. B. A. Forouzan, Data Communications and Networking, 5th ed., McGraw-Hill, 2013: Chapter 10 (Error Detection and Correction; cyclic codes).

Next steps