ENع
←CRC and burst errors
Lesson 69 · Noise, errors and OFDM

CRC: catching burst errors

16 min12 steps5 questionsAdvanced
About this lesson

Noise on a real channel rarely flips one lone bit: a click of interference flips a run of neighbouring bits, a burst. A cyclic redundancy check (CRC) is built to catch exactly that. Follow one by hand: the message 11010011 is read as a polynomial, divided by the generator G = 1011 (x³ + x + 1) using XOR, and the 3-bit remainder 011 rides along as the check. The receiver divides again; remainder 000 means accept. You will see why every burst of up to 3 bits is caught, which longer bursts slip through, and how Ethernet uses the same idea with CRC-32. This goes deeper than the Networking lesson on Ethernet frames; it builds on the lesson on parity and Hamming codes.

You'll learn to

Tick what you feel confident about. These self-checks do not affect your lesson score.

Fig 69 · Interactive
01 / 12

Noise comes in bursts

A spike of interference does not flip one lone bit. It lasts a while, so it flips a run of neighbouring bits: a burst. Here one click flips 3 bits in a row. A single parity bit misses any even number of flips.

line: +1 V = bit 1, −1 V = bit 0
one bit every 1 µs

sent      11010011011
received  11011101011
              ^^^  bits 4, 5, 6 flipped

burst = errors packed close together
(scratches, lightning, a motor switching on)
parity: 2 flips cancel out, unseen
Loading figure…
or ← →
Read the lesson step by step
  1. Noise comes in bursts

    A spike of interference does not flip one lone bit. It lasts a while, so it flips a run of neighbouring bits: a burst. Here one click flips 3 bits in a row. A single parity bit misses any even number of flips.

    line: +1 V = bit 1, −1 V = bit 0
    one bit every 1 µs
    
    sent      11010011011
    received  11011101011
                  ^^^  bits 4, 5, 6 flipped
    
    burst = errors packed close together
    (scratches, lightning, a motor switching on)
    parity: 2 flips cancel out, unseen
  2. Bits as a polynomial

    Read the 8 message bits as coefficients of powers of x: 11010011 is x⁷ + x⁶ + x⁴ + x + 1. Sender and receiver agree on a generator G = 1011, that is x³ + x + 1. It has degree 3.

    bit:     1  1  0  1  0  0  1  1
    power:  x⁷ x⁶ x⁵ x⁴ x³ x² x¹ x⁰
    
    M(x) = x⁷ + x⁶ + x⁴ + x + 1
    G(x) = x³ + x + 1   (bits 1011)
    
    coefficients are only 0 or 1
    and 1 + 1 = 0 (arithmetic mod 2)
  3. Make room: append 3 zeros

    G has degree 3, so the check will be 3 bits long. The sender appends 3 zeros: 11010011000. That is the message times x³, and the zeros hold the place where the check bits will go.

    M(x)·x³ = shift left by 3
    
    11010011  ->  11010011000
    
    11 bits now: 8 message + 3 places
    for the check bits
    
    the bit labels count from the left:
    bit i is the power x^(10−i),
    so bit 0 = x¹⁰ and bit 10 = x⁰
  4. Divide by G with XOR

    Now divide by G the binary way. Wherever the leftmost bit still left is 1, line G up under it and XOR: equal bits give 0, different give 1. No carries, no borrows. Zeros are skipped. 5 XORs clear the message.

    11010011000
    1011        XOR at bit 0
    01100011000
     1011        XOR at bit 1
    00111011000
      1011        XOR at bit 2
    00010111000
       1011        XOR at bit 3
    00000001000
           1011        XOR at bit 7
    00000000011
    
    bits 4, 5, 6 were already 0: skipped
  5. The remainder is the CRC

    What is left in the last 3 places is the remainder, 011: the CRC. The XORs only wiped a working copy; the sender still has the message. The CRC takes the place of the zeros: the frame is 11010011 011.

    remainder R(x) = 011  (= x + 1)
    
    frame T = M·x³ + R
            = 11010011 011
    
    in mod 2, adding R is the same as
    subtracting it, so T = G × (something):
    T divides by G exactly
  6. Send the frame

    The sender puts all 11 bits on the cable: 11010011 then 011. In mod 2, adding the remainder is the same as subtracting it, so the frame is an exact multiple of G. Anything else will not be.

    on the cable: 11010011011
    
    T(x) = x¹⁰ + x⁹ + x⁷ + x⁴ + x³ + x + 1
         = G(x) × Q(x)
    
    3 extra bits for 8 message bits
    (Ethernet: 32 extra bits for up to
     1500 payload bytes)
  7. Receiver: remainder 000

    The receiver divides all 11 bits by the same G, check bits included. A clean frame is a multiple of G, so the remainder is 000. Accept. The receiver never needs a second copy of the message.

    11010011011
    1011
    01100011011
     1011
    00111011011
      1011
    00010111011
       1011
    00000001011
           1011
    00000000000
    
    remainder 000 -> accept
  8. A burst hits: remainder ≠ 000

    Now the burst flips bits 4, 5 and 6. The receiver gets 11011101011. It divides as before and is left with 100, not 000. Reject: the frame is thrown away and sent again.

    sent      11010011011
    error E   00001110000
    received  11011101011
    
    received ÷ G -> remainder 100
    
    remainder ≠ 000 -> reject, retransmit
    (the CRC only detects; it does not
     fix bits like a Hamming code)
  9. Why every short burst is caught

    Received = frame + error E; the frame divides by G, so only E matters. A burst of up to 3 bits is E = xⁱ·B, B of degree below 3. G has degree 3 and a +1 term, so it cannot divide that. Caught.

    received(x) = T(x) + E(x)
    remainder of received = remainder of E
    
    burst here: bits 4, 5, 6 (from the left)
      = powers x⁶, x⁵, x⁴
    E = x⁶ + x⁵ + x⁴ = x⁴·(x² + x + 1)
    
    B has degree < 3: G cannot divide B
    G has the +1 term: G shares no factor
      with xⁱ
    -> G never divides E: caught, every time
    
    plot: every burst length 1..3: 100 %
  10. Some longer bursts slip through

    A burst of 4 bits can be G itself, shifted. Here E = 1011 at bit 5: the remainder is 000 and the bad frame is accepted. Trying every burst: 1 in 4 of length 4 slips, 1 in 8 of longer ones.

    sent      11010011011
    error E   00000101100
    received  11010110111
    
    bits 5, 7, 8 (from the left)
      = powers x⁵, x³, x²
    E = x⁵ + x³ + x² = x²·G(x): a multiple of G
    remainder 000 -> accepted, wrongly
    
    caught, counted over all bursts:
      length 1: 11/11 = 100.0 %
      length 2: 10/10 = 100.0 %
      length 3: 18/18 = 100.0 %
      length 4: 24/32 = 75.0 %
      length 5: 49/56 = 87.5 %
      length 6: 84/96 = 87.5 %
      length 7: 140/160 = 87.5 %
      length 8: 224/256 = 87.5 %
  11. The same division in Python

    A Python integer holds the bits; Python counts bit i from the right, as the power xⁱ. Shifting left by 3 appends the zeros. Walk from bit 10 (lamp 0) to bit 3; where a bit is 1, XOR in G. Left: 0b11, the CRC.

    g = 0b1011           # x^3 + x + 1
    a = 0b11010011 << 3  # 3 zeros
    for i in range(10, 2, -1):
        if a >> i & 1: a ^= g << i-3
    
    >>> bin(a)
    '0b11'      # the CRC 011
    
    a >> i & 1   reads bit i (from the right:
                 Python bit i = lamp 10−i)
    g << i-3     lines G up under bit i
    ^            XOR
    
    (Python 3, integers only)
  12. CRC-32 in every Ethernet frame

    Ethernet does exactly this with a degree-32 generator (0x04C11DB7): 32 check bits per frame. It catches every burst up to 32 bits long. Real CRC-32 also starts from all ones and inverts the result; Python's zlib.crc32 computes it.

    CRC-32 (IEEE 802.3 frame check sequence)
    G = 0x04C11DB7 (+ the x³² term)
    
    bursts ≤ 32 bits: always caught
    33-bit bursts: about 1 in 2³¹ slip
    longer bursts: about 1 in 2³² slip
    
    >>> import zlib
    >>> hex(zlib.crc32(b"123456789"))
    '0xcbf43926'
    
    extra details: register starts at
    0xFFFFFFFF, bits go in low bit first,
    the result is inverted

Quiz Unlocks after the last step.