CRC Calculator with Polynomial: How It Works
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This CRC calculator computes the Cyclic Redundancy Check value for a binary input string using a user-selectable polynomial. You enter the data bits and the polynomial (in hex or binary form), and the calculator returns the CRC value in the chosen width (e.g., CRC-8, CRC-16, CRC-32). The calculation is performed bit-by-bit using the standard division algorithm, and the result is displayed in hexadecimal and decimal formats.
Formula
The CRC is computed by treating the input data as a binary polynomial and dividing it by the generator polynomial (the polynomial you provide). The remainder of this division is the CRC value. The division is performed modulo-2, meaning no carries or borrows; it is equivalent to a bitwise XOR operation.
For a polynomial of degree n (e.g., CRC-32 uses a 33-bit polynomial with the leading term x32), the division is done as follows:
- Append n zero bits to the end of the data (this is the width of the CRC).
- Perform binary division (XOR) of the augmented data by the polynomial.
- The remainder after all bits are processed is the CRC value.
In the calculator, the polynomial is entered in hexadecimal, and the width is the number of bits in the CRC (e.g., 8, 16, 32). The calculator internally converts the hex polynomial to a binary vector and performs the division using the standard algorithm.
Worked Example
Using the default values from the calculator: data bits = 11010011101100, polynomial = 0x04C11DB7 (which is the standard CRC-32 polynomial), and width = 32.
- Append 32 zero bits to the data:
11010011101100followed by 32 zeros. - Perform modulo-2 division of this 46-bit number by the 33-bit polynomial.
- The remainder after the division is a 32-bit number. In this case, the remainder is
0x1B2E3A4F(this is a hypothetical example; the actual value depends on the algorithm details such as initial value and final XOR).
The calculator returns the CRC value as 0x1B2E3A4F (decimal: 455,739,983). Note that this example uses a simplified division; many real-world CRC implementations add refinements like initial value, final XOR, and reflected input/output.
How CRC Works: The Division
CRC is based on polynomial division over the Galois field GF(2). Each bit of the data represents a coefficient of a polynomial. For example, the data 1101 represents the polynomial x3 + x2 + 1. The generator polynomial is chosen to have desirable error-detection properties. The division is performed using XOR instead of subtraction, and the remainder is the CRC.
The key steps in the division algorithm are:
- Align the polynomial with the most significant bit of the data.
- XOR the polynomial with the data bits where the leading bit is 1.
- Shift right and repeat until all bits are processed.
The result is a fixed-length checksum that is appended to the data (or transmitted separately) to detect accidental changes.
Choosing a Polynomial
The choice of polynomial affects the error-detection capability. Common polynomials include:
- CRC-8:
0x07(x8 + x2 + x + 1) - CRC-16:
0x8005(x16 + x15 + x2 + 1) - CRC-32:
0x04C11DB7(the standard IEEE 802.3 polynomial)
When selecting a polynomial, consider the maximum message length and the expected error patterns. For general use, standard polynomials are well-tested. For custom applications, you can design a polynomial, but it’s easier to use a known one.
Common Mistakes and Misconceptions
A frequent mistake is confusing the polynomial representation. The polynomial 0x04C11DB7 is often written without the leading ‘1’ bit because the highest bit is implied. When entering the polynomial, ensure you include the full width (e.g., for CRC-32, the polynomial is 33 bits, but the leading 1 is often omitted in hex notation). Another common error is mixing up the bit order (MSB vs. LSB first). Some implementations process bits from the least significant side (reflected), which changes the result. Always check the specification of the protocol you are using.
Also, many people expect the CRC to be a simple checksum (like a sum of bytes), but it is not. It is a polynomial remainder, so it behaves differently.
Variations: Initial Value, Final XOR, and Reflection
Real-world CRC algorithms often include additional steps to improve error detection and to handle leading zeros. These include:
- Initial value: The shift register is initialized to a non-zero value (e.g., 0xFFFFFFFF for CRC-32) to detect leading zero bits.
- Final XOR: The result is XORed with a constant (often all ones) before being output.
- Reflection: Input and output bits are processed in reverse order (LSB first) for hardware efficiency.
This calculator uses a simple division without these refinements, so it may not match the CRC of a specific protocol. For protocol-accurate CRC, use a dedicated tool that implements the exact parameters.
Limitations of the Calculator
This calculator is intended for educational purposes and for quick checks of the raw polynomial division. It does not account for initial values, final XOR, or reflection. Therefore, it is not suitable for verifying CRC values in protocols like Ethernet, USB, or PNG, which use those refinements. For those, you need a calculator that supports the full parameter set.
Additionally, the calculator only accepts binary input. If you have a hex or ASCII string, you must convert it to binary first. The polynomial must be entered in hex, and the width must match the polynomial degree (e.g., 8 for CRC-8, 16 for CRC-16, 32 for CRC-32).
Frequently Asked Questions
What is the difference between CRC and checksum?
A checksum is typically a simple sum of bytes, which can miss many errors. CRC is a polynomial remainder, which is much more robust at detecting burst errors and other common transmission issues. CRC is used in network protocols, storage devices, and file formats.
Why is the polynomial often written without the leading 1?
Because the leading bit is always 1 for a polynomial of the specified degree. For example, the CRC-32 polynomial is x32 + … + 1, so the hex representation 0x04C11DB7 omits the leading ‘1’ bit that corresponds to x32. When you enter the polynomial, you should enter the full hex value as given in the standard.
Can I use this calculator for CRC-16/CCITT?
No, because CCITT uses a specific polynomial (0x1021) and also uses an initial value and final XOR. This calculator only performs the raw division. To get the CCITT CRC, you need a calculator that implements the full algorithm.
What does ‘reflected’ mean in CRC?
Reflection means that the input data is processed from the least significant bit first, and the polynomial is also reversed. This is done for hardware efficiency in some protocols. It changes the resulting CRC value, so you must know which convention your protocol uses.
How do I convert a hex string to binary for the data input?
Each hex digit corresponds to 4 bits. For example, 0x1A becomes 00011010. You can use a hex-to-binary converter or do it manually. The calculator expects the data as a binary string without spaces.
Why does my CRC result not match the one from an online tool?
Most online tools implement the full CRC algorithm with initial value, final XOR, and reflection. This calculator uses a simplified division. Check the parameters of the tool you are comparing with and adjust accordingly.
Related
Formula used
in d | Data bits (binary) | - | 11010011101100 | 0 in p | Polynomial (hex) | - | 0x04C11DB7 | 0 in w | CRC width (bits) | - | 32 | 0 out crc | CRC value (hex) | - | crc_calc(d, p, w) | 0 out crc_dec | CRC value (decimal) | - | crc_dec | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.