On this page
Every PNG image and every gzip file carries a check value made with a piece of school algebra: polynomial long division. You can do a small one on paper.
What is a cyclic redundancy check?
A cyclic redundancy check is an error-detecting code that appends a short check value, the remainder of a polynomial division, to a block of data (Wikipedia: Cyclic redundancy check). Using cyclic codes this way for error detection was first proposed in 1961, in W. Wesley Peterson and D. T. Brown's paper "Cyclic Codes for Error Detection" (Proceedings of the IRE, January 1961). An n-bit CRC divides by a degree-n generator polynomial, so its remainder is n bits long.
The trick is to read bits as coefficients: 110101 becomes x⁵ + x⁴ + x² + 1. The coefficients live in GF(2), where 1 + 1 = 0, so adding polynomials is XOR on their bits, and subtraction is the same as addition. Our guide to finite fields, with GF(4) and GF(8) built by hand sets this up.
How do you calculate a CRC by polynomial division?
For a generator g(x) of degree n:
Append n zeros to the message (multiplying it by xⁿ).
Under the leftmost 1, write the generator's bits and XOR.
Repeat until fewer than n + 1 bits remain from the leftmost 1.
Send the message followed by the last n bits, the remainder.
The receiver divides the whole block by g(x); remainder zero means no error detected.
Worked example, CRC-3 with g(x) = x³ + x + 1. The generator is 1011. Take the message 110101 and append three zeros: 110101000.
XOR 1011 under bits 1 to 4: 110101000 becomes 011001000.
XOR under bits 2 to 5: 001111000.
XOR under bits 3 to 6: 000100000.
XOR under bits 4 to 7: 000001100.
Bit 5 is now 0, so skip to bit 6 and XOR under bits 6 to 9: 000000111.
The remainder is 111, so you send 110101111.
Check with algebra: modulo g(x), x³ ≡ x + 1, so x⁵ ≡ x² + x + 1, x⁷ ≡ 1 and x⁸ ≡ x. Then x⁸ + x⁷ + x⁵ + x³ ≡ x + 1 + (x² + x + 1) + (x + 1) = x² + x + 1. That is 111 again.
The receiver divides 110101111 by 1011 and gets 000. If bit 3 flips and 111101111 arrives, the error is x⁶ ≡ x² + 1, so the remainder is 101: caught.
Why does a CRC catch single-bit errors and short bursts?
The received block is T(x) + E(x): what was sent plus the flipped bits. T(x) is a multiple of g(x), so the remainder comes from E(x) alone. An error slips through only if g(x) divides E(x).
Single-bit errors. E(x) = xⁱ. A generator with two or more terms, including + 1, never divides a lone power of x.
Bursts of length n or less. A burst starts and ends with a flipped bit, so E(x) = xⁱ·B(x) with B(x) of degree below n and constant term 1. Since g(x) shares no factor with xⁱ, it would have to divide B(x), which is nonzero and smaller. Impossible.
Bursts of length n + 1 can slip. The length-4 bursts for CRC-3 are 1001, 1011, 1101 and 1111; only 1011, which is g(x) itself, is missed.
This matches the general rule: an n-bit CRC typically detects any single burst not longer than n bits, and for longer bursts the fraction detected is about 1 − 2⁻ⁿ (Wikipedia: Cyclic redundancy check).
Where is CRC-32 used?
CRC-32 uses a degree-32 generator, so its check value is 32 bits. The PNG image format ends every chunk with a CRC-32 whose polynomial is identical to gzip's (W3C PNG specification); PNG also starts the register at all 1s and inverts the result, but the core is the division above. A gzip file stores the CRC-32 of the uncompressed data, computed by the algorithm of ISO 3309 and ITU-T V.42 (RFC 1952). The same polynomial, 0x04C11DB7, is listed for Ethernet, Wi-Fi, SATA, PCI Express and ZIP (Wikipedia: Cyclic redundancy check).
A CRC guards against accidents, not attackers: anyone who edits a file can recompute a matching CRC, so deliberate changes need cryptographic tools (Wikipedia: Cyclic redundancy check).
How should you practise CRC division?
Redo the worked example without looking; check it with x³ ≡ x + 1.
Compute the CRC-3 of your own 6-bit message, flip one bit and confirm the remainder changes.
Explain why 1011 is the only length-4 burst CRC-3 misses.
For another code built on a binary trick, read Gray code, step by step. To revisit polynomials and remainders, the Fermi Concept Library covers concepts across mathematics and computing. When a division keeps coming out wrong, the Fermi Problem Library has a step-by-step solver that explains the reasoning rather than just printing an answer.



