Computing Library › Number Systems & Information
Number Systems & Information

Cyclic Redundancy Check

A CRC treats data as a polynomial and uses its remainder under division to detect errors robustly.

Polynomial arithmetic

A CRC views the message bits as coefficients of a polynomial over the field with two elements, where addition is XOR. The message is divided by a fixed generator polynomial, and the remainder becomes the check value.

Computing the CRC

Kronos motion — data assimilation

Append zeros equal to the CRC width, then perform polynomial long division by the generator using XOR at each step. The remainder is appended to the message. The receiver divides the whole thing; a zero remainder means no detected error.

Why it is strong

A well-chosen generator guarantees detection of all single- and double-bit errors, all errors affecting an odd number of bits, and any burst of errors shorter than the CRC width. This makes CRCs far stronger than additive checksums.

Standard polynomials

Widely used generators include CRC-32 in Ethernet and ZIP, CRC-16 in many serial protocols, and CRC-8 in small embedded messages. Each is specified by its generator polynomial and initial value.

Implementation

Bit-by-bit division is simple but slow; table-driven implementations process a byte at a time using a precomputed 256-entry lookup table, and hardware does it with a shift register and XOR taps.

Limits

A CRC detects accidental errors extremely well but offers no security: an attacker can alter data and recompute a matching CRC. Integrity against tampering needs a cryptographic hash or authentication code.

python
def crc8(data, poly=0x07):
    crc = 0
    for byte in data:
        crc ^= byte
        for _ in range(8):
            crc = ((crc << 1) ^ poly) & 0xFF if crc & 0x80 else (crc << 1) & 0xFF
    return crc