Introduction
Noise, interference and faulty hardware flip bits. A receiver that cannot tell a damaged frame from a good one will pass garbage upward. Error detection adds redundant bits computed from the data; the receiver recomputes them and compares. If they disagree, the frame is discarded (and, if the protocol provides it, retransmitted). Error correction adds enough redundancy to locate and fix the flipped bits without retransmission.
On wired links errors are rare, so networks mostly detect and retransmit. The three detection schemes that matter are parity (one bit or a two-dimensional grid of bits), the Internet checksum (a 16-bit ones' complement sum used in IP, UDP and TCP), and the cyclic redundancy check (CRC, used in Ethernet frames, covered in Cyclic Redundancy Check (CRC)). The common language for comparing them is Hamming distance.
Before any check can be applied, the receiver must know where a frame starts and ends. That is framing. A receiver can find frame boundaries with a length field, byte stuffing, bit stuffing, or physical-layer coding violations.
Prerequisites
- Layering, OSI and TCP/IP Reference Models: which layer computes which check.
- XOR and modulo-2 arithmetic: , ; Boolean Algebra under "Related topics" reviews XOR.
Core concepts
Error types
| Term | Meaning |
|---|---|
| Single-bit error | Exactly one bit of the data unit is flipped |
| Burst error of length | The first and last flipped bits are positions apart (counting both ends); bits in between may or may not be flipped |
| Codeword | A data word plus its check bits: bits for data and check bits |
| Code rate | , the fraction of useful bits |
Hamming distance
The Hamming distance between two equal-length words is the number of positions where they differ, which is the number of 1s in . The minimum distance of a code is the smallest distance between two different codewords.
Reason: flips can turn a codeword into another codeword only if . For correction, the received word must stay strictly closer to the sent codeword than to any other, which needs the spheres of radius around codewords to be disjoint.
Detection versus correction. A code with detects 3 errors or corrects 1 (and detects 2 while correcting 1), but it cannot correct 3. The two uses compete for the same distance.
Single parity bit
Append one bit so that the number of 1s is even (even parity) or odd (odd parity). : every odd number of flipped bits is detected, every even number is missed. It is cheap and weak.
Two-dimensional parity
Arrange the data as a grid, add a parity bit to every row and every column, plus a corner bit (the parity of the parity row, which equals the parity of the parity column). :
- every 1-, 2- or 3-bit error is detected;
- a single-bit error is located (its row and column both fail) and so can be corrected;
- some 4-bit errors are missed: four flips at the corners of a rectangle leave every row and column parity unchanged.

The Internet checksum
Used in the IPv4 header (header only), and in UDP and TCP (over a pseudo-header, the transport header and the data). The data is treated as a sequence of 16-bit words:
- Add the words using ones' complement addition: add normally, and whenever a carry comes out of bit 15, add it back into bit 0 (end-around carry).
- The checksum is the ones' complement (bitwise NOT) of the sum.
- The receiver adds all words including the checksum. The result is 0xFFFF (all ones) if no error is detected.
If the data has an odd number of bytes, a zero byte is appended for the computation only. The order in which the words are added does not matter, and the end-around carries can be folded at the end instead of after every addition: both give the same result.

What the checksum misses. Because addition is commutative, swapping two 16-bit words gives the same checksum. Two errors that add some value to one word and subtract it from another in the same bit column cancel. Its strength is speed in software, not error coverage; that is why links use a CRC and the checksum is the end-to-end backstop.
How it works: framing before checking
A receiver finds frame boundaries in one of four ways: a length field (fragile, because a corrupted count loses synchronisation), byte stuffing, bit stuffing, or physical-layer coding violations.
Byte stuffing. Each frame starts and ends with a special FLAG byte. If a FLAG byte occurs inside the data, the sender inserts an ESC byte before it; an ESC in the data is also preceded by an ESC. The receiver removes every ESC and treats the next byte as data. The overhead depends on how many FLAG and ESC bytes the data contains; in the worst case the frame doubles.
Bit stuffing. Each frame is bounded by the flag pattern 01111110. Inside the frame, the sender inserts a 0 after every run of five consecutive 1s, whatever the next bit is. The receiver deletes the 0 that follows any five consecutive 1s. Six 1s in a row can then occur only in a flag. The frame can be any number of bits, not a whole number of bytes.
Bit versus byte stuffing. Byte stuffing works on whole bytes and needs two special byte values; bit stuffing works on the bit stream and needs one 8-bit flag pattern. A question about "how many bits are added" means bit stuffing: count runs of five 1s, restarting the count after each inserted 0.
Mathematical explanation
Parity detects exactly the odd-weight errors. The parity of the received word is the parity of the sent word XOR the parity of the error pattern. The check fails exactly when the error pattern has an odd number of 1s.
Check bits needed for single-error correction (Hamming bound for ). Each of the positions, plus "no error", must have its own syndrome among the values:
For this gives ; for , ; for , ; for , .
Ones' complement sum. Adding with end-around carry is addition modulo on the 16-bit values (with 0x0000 and 0xFFFF both representing zero). If the sum of the data words is , the checksum is , and (ones' complement) is 0xFFFF.
Worked examples
Example 1: minimum distance of a code
Code . Distances: , , , , , . So : the code detects up to 2 errors or corrects 1.
Example 2: parity bits
The 7-bit word 1011001 has four 1s. Even parity bit: 0 (codeword 10110010). Odd parity bit: 1. If bits 2 and 5 flip, the received word still has even weight and the error is missed.
Example 3: two-dimensional parity
For the block in Figure 1, the row parities are 1, 0, 0, 0, the column parities 0, 1, 0, 0, and the corner bit 1. If the bit in row 2, column 3 flips, row 2 and column 3 fail and the receiver flips that bit back. If the four bits at rows 1 and 3, columns 1 and 3 (all 1, 1, 1, 0 in the data) all flip, every check still passes.
Example 4: the Internet checksum
Words 0x4F2A, 0xB3C1, 0x9E07. ; end-around carry gives 0x02EC. . Checksum . Receiver: with end-around carries is 0xFFFF. Swapping the first two words before sending gives the same checksum, so a reordering of these words is not detected.
Example 5: bit stuffing
Data 0111111111100 (13 bits) becomes 011111011111000 (15 bits): a 0 is inserted after the first five 1s and after the next five. The flag pattern 01111110 sent as data becomes 011111010. Fourteen 1s in a row become 1111101111101111 (two inserted zeros: after the 5th and the 10th original 1).
Example 6: byte stuffing and destuffing
Data bytes A, FLAG, ESC, B. The sender puts an ESC before the FLAG and before the ESC, then adds the delimiting flags: FLAG A ESC FLAG ESC ESC B FLAG, 8 bytes for 4 data bytes. A receiver that finds ESC ESC ESC FLAG inside a frame delivers ESC FLAG: each ESC makes the byte after it ordinary data.
Bit destuffing runs the other way. The bits 0111110111110110 received between two flags contain two stuffed 0s, each right after five 1s; deleting them gives the 14 data bits 01111111111110.
Related material. Hamming (7,4) code
Positions 1 to 7; parity bits at positions 1, 2 and 4; even parity; position is covered by the parity bit when bit of is 1. Data 1011 in positions 3, 5, 6, 7 gives check bits , , and the codeword 0110011. If position 5 flips (received 0110111), recomputing the three checks gives the syndrome , which is 5: the receiver flips position 5. , so two errors are miscorrected rather than detected.
Important properties and observations
- Coverage summary.
| Scheme | Detects | Misses | |
|---|---|---|---|
| Single parity | 2 | All odd-weight errors | All even-weight errors |
| 2D parity | 4 | All errors of 1, 2, 3 bits; corrects 1 | Some 4-bit rectangles |
| Internet checksum | 2 | All single-bit errors; most others | Word reorderings, compensating errors |
| CRC with check bits | depends on generator | All bursts of length (generator with a constant term); all odd-weight errors if divides the generator | About a fraction of longer bursts |
- The IPv4 checksum covers only the header and is recomputed at every router because TTL changes. UDP and TCP checksums cover data and are end to end.
- 0x0000 and 0xFFFF. In ones' complement both mean zero. UDP over IPv4 uses a transmitted checksum of 0 to mean "no checksum"; a computed value of 0 is sent as 0xFFFF.
Common misconceptions.
- "Parity detects any single error and any double error." Double errors are always missed by single parity.
- " detects 3 errors." It detects 2.
- "The checksum is added in ordinary binary." Carries out of the top bit wrap around; ignoring them gives a wrong checksum.
GATE examination perspective
- Distance rules. Detect : . Correct : . Compute by checking all pairs (or, for a linear code, the minimum weight of a non-zero codeword).
- Check-bit count. Smallest with .
- Checksum arithmetic. Add in hexadecimal, fold carries back, complement. Verify by adding the checksum: the total must be FFFF.
- 2D parity. Which error patterns escape: four corners of a rectangle.
- Stuffing. Bit stuffing inserts after five 1s; byte stuffing escapes FLAG and ESC. Count carefully across runs longer than five.
Summary
Sources
- A. S. Tanenbaum, D. J. Wetherall, Computer Networks, 5th ed., Pearson, 2011: Section 3.1.2 (Framing), Section 3.2.1 (Error-Correcting Codes) and Section 3.2.2 (Error-Detecting Codes).
- J. F. Kurose, K. W. Ross, Computer Networking: A Top-Down Approach, 8th ed., Pearson, 2021: Sections 6.2.1 (Parity Checks) and 6.2.2 (Checksumming Methods).
- B. A. Forouzan, Data Communications and Networking, 5th ed., McGraw-Hill, 2013: Chapter 10 (Error Detection and Correction).
- R. Braden, D. Borman, C. Partridge, RFC 1071, Computing the Internet Checksum, 1988, Sections 1 and 2, (consulted 2026-11-11).
- J. Postel, RFC 768, User Datagram Protocol, 1980 (checksum of zero means none transmitted), (consulted 2026-11-11).