I know the whole intention of using CRC is to do error detection, but I heard someone state that it can be used to do basic error correction in addition to error detection. I was curious if this was the case, and if so, how powerful is it? I mean, we usually refer to CRC as capable of performing x-bit detection, but I'm curious if it is capable of performing x-bit correction. If so, how does this work? Thanks.
4 Answers
It is possible to do single-bit error correction with a CRC. Assume one has a CRC "register" and has functions to run the CRC algorithm forward and backward a bit at a time, ignoring incoming data
int crc_forward(int old_value, int data_bit) { if (old_value & 0x8000) return ((old_value ^ 0x8000) SHL 1) ^ 0x1021 ^ data_bit; else return (old_value SHL 1) ^ data_bit; } int crc_reverse(int old_value) { if (old_value & 1) return (old_value SHR 1) ^ 0x8810; else return old_value SHR 1; }
Suppose one has a packet which is computed so that initializing the crc to some value and running crc_forward for each bit (MSB first) should yield zero. If one gets a CRC value other than zero, one can run the algorithm in reverse (ignoring data bits) until the computed CRC value is 1. That's the location of the incorrect bit.
Note that this approach may be adequate for software error correction in things like NAND flash. To usefully employ it for hardware error correction, one would have to either be able to delay read operations until the ECC could be processed, or else one would need a table of 'syndrome' values and bit positions.

- 77,689
- 9
- 166
- 211
-
It's also possible to implement single burst correction. Some 16 bit CRC polynomials allow for single bursts of 7 bits in messages up to 184 bits to be corrected. – rcgldr Apr 30 '19 at 22:24
You CAN do multi-bit error correction with CRCs. Looking at wikipedia, with references to koopmans work, a CRC can detect up its hamming_distance-1 errors. The hamming distance depends on the payload length, and the CRC polynomial in use. So for example Koopmans polynomial of 0xBA0DC66B can detect up to 5 bits of error in messages up to 16360 bits long. The algorithm described in the previous two messages can be extended up to as many bits as needed, but the time goes up exponentially with the number of bits to fix.
- Calculate error CRC = CRC_gotten ^ CRC_expected.
- Look through all possible 1 bit messages (ie all 0s, a 1, and all 0s) (there are message_length cases to evaluate. Note this is BITS not BYTES) and the error bit is the message that generates the error CRC.
- Invert the detected bit to correct the error.
If you can't find 1 bit matching the error CRC, look through all 2-bit, 3-bit up to your hamming_distance-1. Note that this gets slow fast, message_length squared for 2 bits, cubed for 3 bits up to fifth power for five bits.

- 171
- 2
- 3
-
The indicated algorithm as worded would seem to be n-squared for single-bit errors, n-cubed for two-bit errors, etc. since it calculating the CRC for each message independently would take time N. It might be helpful to suggest how it might be done without that extra factor of N. – supercat Oct 21 '15 at 15:06
-
No, N for single bits. I can calculate the CRC of a single bit set in N bits in logN time. Better, given the CRC of a single bit at position X in an N bit message, I can tell you the CRC of the message with bit at N+1 trivially. That is just a single step of the CRC inner loop. – ilgitano Oct 07 '17 at 14:56
-
just your crc_forward function in a loop: starting from 1, crc_forward, is that the crc error? no, crc_froward and check again. – ilgitano Oct 08 '17 at 12:32
-
2This is a bit misleading… just because you can _detect_ 5 single bit errors, does not mean you can also _correct_ them. In practice, only 2 single bit errors can be (usually) corrected for a message of the size you've given – this follows simply from the pigeonhole principle (there are on average over 1000 possibilities for 3 bit errors in a message of length 16360 to produce a given CRC). A single burst error is a completely different story, of course – in this case, *all* 33 bit bursts except for the generator polynomial can be detected and correction length should be >10b for <=16360b msg. – Arne Vogel Nov 02 '18 at 19:21
-
1@Arne, koopsmans work includes a table telling you data lenght where the error CRC stops being unique for a given number of bits. As long as your message is shorter than that, the error code will be unique. That of course depends on the polynomial used. – ilgitano Apr 29 '21 at 18:06
I recently worked on CRC16 error detection and single bit error correction.
Here's the basic idea:
- Assume you have a single bit error.
- If the data+crc includes no error, the CRC will be 0, else it is not.
- We define the CRC sent as CRCs and CRC received as CRCr.
- Then the error bits are given by
CRCox = CRCs ^ CRCr
. - The result encompasses both CRC errors and data errors.
- Have look at what relationship between CRCox and the bit error is.
Is this clear? I have a paper about this. If you want to know more, just let me know.

- 12,225
- 19
- 71
- 86

- 565
- 7
- 19
-
I think this **may** be the paper @Wandy is referring to: http://espace.library.uq.edu.au/eserv.php?pid=UQ:9523&dsID=n01393289.pdf – Jason Sundram Mar 17 '12 at 15:49
-
1For point 2, it is not the CRC which will be 0. It is the CRC received XORed with the CRC calulated on the received data! – Étienne Jan 29 '14 at 14:16
-
@Étienne certainly he meant that the CRC of the received data+crc would be zero – Steve Cox Nov 13 '15 at 22:05
Late answer, but CRC32 polynomial
0x1f1922815 (= 0x787 * 0x557 * 0x465 * 0x3 * 0x3)
can detect up to 7 bit errors and correct up to 3 bit errors for a 1024 bit (992 bit data, 32 bit CRC) message. There are comb(1024,1) + comb(1024,2) + comb(1024,3) = 178957824 correctable bit error patterns. If there is enough memory for a 1431662592 byte table (178957824*8 = ~1.4 GB), then all possible 1, 2, and 3 bit error CRC's could be generated and stored in that table, where each entry would be: 32 bit CRC, a 2 bit error count, and three 10 bit fields for bit error locations.
The table would then be sorted, and when checking a CRC, if it is bad, a binary search of the table (max 28 loops) could determine if it was a 1, 2, or 3 bit error case and corrected using the indexes stored in the table.
However, there is a possibility of mis-correction with 5 or more bit errors. If some 5 error bit pattern produces the same CRC as a 3 error bit pattern, the wrong 3 bits will be changed, resulting in an 8 bit error that appears to have a valid CRC.
Link to example code:

- 27,407
- 3
- 36
- 61