Error Detection and Correction
Error detection tells a receiver that data has changed. Error correction uses extra information to recover the original data within the limits of the code. A parity bit can flag a single flipped bit. Hamming code can locate and repair it. When a frame fails a check such as a CRC, the protocol can discard it or request another copy.
The second bit changed. What can the receiver infer from its check bits?
What is the difference between error detection and correction?
The sender encodes a message into a codeword containing data and redundant check bits. At the receiver, a failed check is evidence of corruption. Repair requires enough redundancy to distinguish which original codeword was sent, or another copy from the sender.
- Detect
- “Something changed.” Even parity flags an odd number of flipped bits but cannot identify their positions.
- Correct
- “Bit 5 changed.” With one error, a Hamming decoder identifies the position from the failed checks and reverses the flip.
- Retransmit
- “Send that frame again.” Automatic repeat request (ARQ) replaces a missing or rejected frame when feedback and time permit.
What happens when the same two bits flip?
Send 1011 through three encoders. Each adds its own check bits. Change the same data positions in every transmission and leave the check bits alone.
Two flips. The first and second data bits change and 1011 arrives as 0111.
Single parity
Misses the errorEven count. Parity check passes.
Delivers 0111Hamming (7,4)
Miscorrects the wordSyndrome 110. Decoder flips position 6.
Delivers 0101Extended Hamming (8,4)
Rejects the wordSyndrome 110. Overall parity is even.
No payload deliveredThe receiver sees only its received codeword. We know when it delivers the wrong answer because this experiment also records the transmitted message.
Error detection and correction techniques compared
Start with the job the receiver must do. A failed Ethernet frame check can justify dropping a frame. A memory controller usually needs the correct word on that same read.
| Technique | Purpose | Main capability | Common uses |
|---|---|---|---|
| Parity (VRC) | Detect | All odd numbers of flips; misses all even numbers | Simple serial words |
| Two-dimensional parity | Detect / correct | Locates one flipped bit with complete row and column checks | Block checks, teaching |
| Checksum | Detect | Many corruption patterns; cancellation and reordering can escape | Internet protocol checks |
| CRC | Detect | Strong burst-error detection; strength depends on generator and length | Ethernet frame check sequence |
| Hamming code | Correct | Single-error correction (SEC) | Short blocks, coding fundamentals |
| Extended Hamming | Correct / detect | Single-error correction, double-error detection (SECDED) | ECC memory |
| Reed–Solomon, LDPC, polar, convolutional | Correct (FEC) | Code-dependent multi-error recovery | Storage, radio, cellular, satellite |
| ARQ | Recover by retry | Resends missing or rejected frames | Two-way packet links |
Correction capability depends on the actual code, decoder and error pattern. FEC is a category, not a single code; both Hamming and Reed–Solomon are FEC methods.
Error detection and correction simulator
Choose a code and enter your data, or start with a preset. Select any received bit to flip it. Compare the receiver’s decision with the message that was actually sent.
Extended Hamming (8,4)
01100110Example: position 5 was flipped by the channel. Positions count from left to right.
0110111001100110Overall parity check: 1 (odd total, mismatch).
Educational bit-flip model, no analog channel or random noise. The receiver only uses the received bits and check rules; the simulator separately compares against the transmitted data to expose undetected errors and miscorrections. CRC here uses MSB-first, zero-initialized, unreflected polynomial division, not a named production CRC profile.
Types of errors in data communication
The number of changed bits and their positions both matter. A code designed for isolated bit flips may struggle with several closely spaced errors.
Single-bit error
Exactly one bit changes. A single-error-correcting code can locate and repair that bit.
Multiple-bit and burst errors
Multiple bits change. A burst’s length is the span from the first changed bit to the last, including any unchanged bits in between. A four-bit burst need not contain four incorrect bits.
Random thermal noise can cause scattered bit errors, while fading, impulse noise or interference may produce bursts. Missing frames and out-of-order packets are separate protocol problems; bit-level checks alone cannot detect every such event. Learn how noise in communications affects SNR and BER.
An erasure gives the decoder extra information. If a symbol is missing or the receiver marks it unreliable, its position is known. For a block code of minimum distance d, unique recovery is guaranteed for e unknown errors and s known erasures when 2e + s < d. A distance-3 code can therefore recover one unknown bit error or two erased positions.
Parity checks: VRC, LRC, and two-dimensional parity
A parity bit makes the total count of 1s in a protected word even or odd. For even parity, the check bit is the XOR of the data bits. The receiver computes parity again over the complete word. Vertical redundancy check (VRC) commonly means adding a parity bit to each data unit.
⊕ means XOR (addition modulo 2). For odd parity, invert P.
Worked example: even parity of 1011001
The seven data bits contain four 1s. Add a 0 to make the count even.
A single flip changes the total to an odd number, so it is detected. Flipping two bits preserves even parity, so the corrupted word can pass. Single parity detects every odd number of flips, no even number, and cannot locate the error.
Longitudinal redundancy check (LRC) and two-dimensional parity
LRC typically adds a parity word across a group of equally sized data units. Combining column parity with a parity bit for each row produces two-dimensional parity. Under a single-bit-error assumption, the failed row and column intersect at the flipped bit.
One error: row and column fail
Four errors: the rectangle escapes
These examples use complete even row and column parity, including the corner bit. Multiple errors may produce ambiguous syndromes; the receiver must not assume every reported intersection represents a single error.
Internet checksum: add, fold, and complement
A checksum summarizes a block of data using arithmetic. For the 16-bit Internet checksum, split the protected bytes into 16-bit words, add them using one’s complement arithmetic (wrap a carry from the top back to the low bit), then complement the result. The checksum is included in the protected data according to the protocol.
Worked example: 16-bit one’s complement checksum
Let the words be ABCD and EF01 (hexadecimal).
ABCD + EF01 = 19ACE9ACE + 1 = 9ACF~9ACF = 65309ACF + 6530 = FFFFChecksum = 0x6530. In this example the receiver checks for a folded sum of all 1s (equivalently, a complemented result of zero).
Checksums are inexpensive and catch many common corruptions, but different word sequences can have the same sum. Swapping the two 16-bit words above changes their order without changing this checksum. The IPv4 header checksum and TCP/UDP Internet checksums use related one’s complement arithmetic with protocol-specific protected fields. See RFC 1071 for computation details.
Calculate a 16-bit Internet checksum
Each entry is a 16-bit word in hexadecimal. For an odd number of bytes, add a zero byte at the end for the calculation. For example, bytes 12 34 AB form the words 1234 AB00.
Checksum 0x6530 · Folded sum 0x9ACF
Show the running sum
- 0000 + ABCD = ABCD
- ABCD + EF01 = 19ACE → fold carry → 9ACF
Cyclic redundancy check (CRC) with a worked example
A CRC treats a bit string as coefficients of a binary polynomial. The transmitter appends the remainder of polynomial division by an agreed generator to the data. The receiver checks the resulting codeword against that same generator. Division uses XOR instead of ordinary subtraction, with no carries or borrows.
G(x) is the generator of degree r; R(x) contains r check bits. All operations are over GF(2).
CRC solved example: data 1101, generator 1011
The generator is x³ + x + 1, so append three zeros to 1101. Perform modulo-2 division on 1101000.
Show the four XOR division steps
Starting word: 1101000 · Generator: 1011
Step 1 · XOR starting at position 1
110100010110000110000Step 2 · XOR starting at position 2
011000001011000011100Step 3 · XOR starting at position 3
001110000101100001010Step 4 · XOR starting at position 4
0001010000101100000013-bit remainder = 001
Remainder = 001; transmitted codeword = 1101001. Dividing the codeword by 1011 gives zero remainder. If position 5 flips, the received word is 1101101 and the remainder becomes 100, so the receiver detects an error.
Which errors can a CRC detect?
A conventional generator with nonzero constant term and degree r detects every nonzero burst of length at most r. A generator containing the factor x + 1 detects every odd-weight error pattern. Longer burst and multi-bit guarantees depend on the polynomial and protected block length. Under suitable random-error assumptions an r-bit CRC has an approximate undetected-error probability of 2−r, but this is not a guarantee for arbitrary patterns.
For this simple example, an error polynomial of 0001011 (the generator itself) produces a zero remainder. The codeword changes from 1101001 to 1100010 and passes the check. CRC detection is strong, not infallible. Production CRCs also specify initialization, reflection, final XOR and byte order, so their check residues need not be zero.
Hamming code and SECDED: finding the bad bit
Hamming codes use overlapping parity checks to identify a single changed bit. The standard binary Hamming (7,4) code protects four data bits with three parity bits. With positions numbered from 1 on the left in this guide, parity bits occupy powers of two: 1, 2 and 4. Data bits occupy 3, 5, 6 and 7.
Choose the smallest integer r satisfying this inequality for k data bits. For k = 4, r = 3, because 8 ≥ 4 + 3 + 1.
Hamming (7,4) encoding and parity positions
Worked example: encode 1011 and correct bit 5
- Place data 1011 in positions 3, 5, 6 and 7, in that order.
- P1 = d3 ⊕ d5 ⊕ d7 = 1 ⊕ 0 ⊕ 1 = 0.
- P2 = d3 ⊕ d6 ⊕ d7 = 1 ⊕ 1 ⊕ 1 = 1.
- P4 = d5 ⊕ d6 ⊕ d7 = 0 ⊕ 1 ⊕ 1 = 0.
At the receiver, recompute parity over positions {1,3,5,7}, {2,3,6,7} and {4,5,6,7}. The check bits are s1 = 1, s2 = 0, s4 = 1, giving syndrome s4s2s1 = 101₂ = 5. Flip bit 5, then extract positions 3, 5, 6 and 7 to recover 1011.
Extended Hamming (8,4): single-error correction, double-error detection
Adding an overall even-parity bit at position 8 raises the minimum distance to 4. The three-bit syndrome from positions 1–7 and the overall parity check let the receiver distinguish one- and two-bit errors under the assumption that at most two bits are wrong.
| Syndrome S | Overall parity check P | Decoder action (≤ 2 flips) |
|---|---|---|
| 0 | 0 | Accept; no error indicated |
| Nonzero | 1 | Correct position S in bits 1–7 |
| 0 | 1 | Correct overall parity bit (position 8) |
| Nonzero | 0 | Flag double error; do not correct |
Triple and higher error counts can cause miscorrections or false accepts. Use the simulator to see the difference between SEC and SECDED by injecting two errors into the same original data.
Forward error correction (FEC) vs. retransmission (ARQ)
FEC sends redundant information proactively so a receiver can recover data without requesting another copy when errors are within its capability. ARQ (automatic repeat request) uses detection, sequence information, acknowledgments and timeouts to recover by retransmission.
FEC: repair locally
ARQ: request another copy
Common forward error correction codes
- Block codes
- Map a fixed data block into a longer codeword. Hamming corrects a single bit; Reed–Solomon corrects symbol errors. For a conventional RS(n,k) code, up to floor((n−k)/2) unknown symbol errors can be corrected, under the usual bounded-distance model.
- Convolutional codes
- Produce redundant output using current and previous input bits. A Viterbi decoder can estimate the most likely transmitted sequence.
- LDPC and polar codes
- Modern code families used in high-performance digital links. LDPC uses sparse parity-check constraints and iterative decoding; polar coding constructs channels of different reliability. For example, 5G NR uses LDPC for shared-channel data and polar coding for certain control channels.
Common ARQ protocols
Stop-and-wait sends one outstanding frame at a time. Go-back-N uses a sliding window and can resend a rejected frame plus following frames. Selective repeat can resend specific missing or rejected frames. Hybrid ARQ combines FEC with retransmission and, in many designs, combines information from multiple received attempts.
Adding FEC can increase processing and coding delay, but it may reduce retry delay and improve usable throughput on noisy links. Interleaving spreads bursts across multiple codewords; it does not correct errors by itself and adds buffering latency.
Error-control formulas: Hamming distance, code rate and BER
Hamming distance
Count the positions where two words differ. The minimum distance dmin is the smallest distance between distinct valid codewords.
For 101100 and 100110, positions 3 and 5 differ, so d = 2.
Guaranteed error capability
Correction: ⌊(dmin − 1)/2⌋
These are separate bounded-error guarantees, not simultaneous maxima. To guarantee correcting t errors and detecting up to s errors in total (s ≥ t), use dmin ≥ t + s + 1.
Code rate and overhead
Overhead = (n − k)/k × 100%
k is information bits; n is transmitted codeword bits. Overhead here is relative to the original data, not the final codeword.
Bit error rate (BER)
Report whether BER is measured before or after decoding, and which bit population is used. Frame error rate (FER) instead measures erroneous frames out of frames evaluated.
Example: code overhead and information rate
For Hamming (7,4), the rate is 4/7 ≈ 0.5714. The data-relative overhead is 3/4 = 75%; redundancy occupies 3/7 ≈ 42.86% of each transmitted codeword. At a raw coded rate of 7 Mb/s, the nominal information rate is 4 Mb/s, excluding framing, retransmission and other overhead.
Example: probability of errors in a frame
If independent bit flips have probability p, an uncoded n-bit frame has probability 1 − (1 − p)n of containing at least one error. For p = 10−5 and n = 1,000 bits, the probability is about 0.995%. The chance of exactly one flip is np(1 − p)n−1. For a single-error-correcting codeword the probability of two or more flips is 1 − (1 − p)n − np(1 − p)n−1. This is the probability of exceeding the guaranteed one-bit correction capability, not necessarily the measured residual BER. Burst errors violate the independence assumption.
Applications in computers and communication networks
Frame integrity
Ethernet uses a CRC-based frame check sequence to reject corrupted frames. Higher layers may retry depending on the protocol; the FCS itself does not reconstruct the frame.
ECC RAM and storage
SECDED and more advanced ECC schemes protect memory words. Storage systems may combine checksums, multi-symbol correction codes and redundancy across devices.
Wi-Fi and cellular
Physical-layer codes improve reception while packet checks and retry mechanisms handle residual corruption. Systems can adapt modulation and code rates as link quality changes.
Satellite and deep-space communication
Low received power and long round-trip delay make strong FEC especially valuable. Interleaving and suitable modulation/coding combinations help maintain reliable links.
How engineers choose an error-control scheme
Start with the permitted residual error rate and the link’s measured error pattern. Evaluate code rate, decoding complexity, block length, energy and latency together. If a return link exists, compare FEC with ARQ or hybrid ARQ; if not, prioritize appropriate FEC and independent integrity checks. Validate under realistic burst errors, fading and interference rather than relying solely on an independent-bit model.
CRC and checksums address accidental corruption. They are not authentication mechanisms: an attacker can deliberately change data and recompute a public check value. Use cryptographic authentication when malicious modification is a concern.
Frequently asked questions
Can CRC correct errors?
Typical communication protocols use CRC to detect corruption and reject the frame, not correct it. Although specialized algorithms may exploit known error constraints, a CRC check alone normally does not uniquely identify the original frame.
How many errors can Hamming code correct?
Standard Hamming codes with minimum distance 3 guarantee correction of one bit error. Extended Hamming codes with distance 4 support SECDED: correct one bit error and detect two, without miscorrecting the two-bit case.
Why is CRC usually stronger than a checksum?
A carefully chosen CRC polynomial can give explicit guarantees for burst errors and certain multi-bit patterns. An additive checksum can miss changes that cancel each other or reorder whole words. Compare exact algorithms and protected lengths, rather than assuming that every CRC is stronger than every checksum.
Can error detection guarantee perfect data?
No finite redundancy scheme can detect all possible corruptions of arbitrary severity. A damaged codeword may be changed into another valid one. Define bounded-error guarantees and measure the probability of undetected error for the intended channel.
How many check bits are needed for 8 data bits?
For a single-error-correcting shortened binary Hamming code, four check bits suffice. Three would give 8 syndromes for 12 possibilities (11 bit positions plus no error). Four give 16 syndromes for 13 possibilities. Adding an overall parity bit produces a 13-bit SECDED word with 8 data bits.
References and further study
The worked examples use even Hamming parity and number codeword positions from the left. These sources cover the underlying codes, their guarantees, and the Internet checksum convention.
- University of California San Diego — CS 123, Data Link Error Detection.
- University of Michigan — EECS 489, Error Control.
- University of British Columbia — ELEX 3525, Error Detection and Correction.
- RFC 1071 — Computing the Internet Checksum.
- Shu Lin and Daniel J. Costello, Jr., Error Control Coding, 2nd edition, Pearson, 2004. Block and convolutional codes, bounds and decoding.
- University of Illinois · ECE 120 notes — Hamming distance and the single-error correction, double-error detection guarantee.