During data transmission, bits may change because of noise, interference, signal problems, or hardware faults.
For example, the sender sends:
Sender Receiver
10110110 ───────────→ 10100110
↑
Error
The Data Link Layer uses error detection and correction techniques to identify and sometimes correct these errors.
1. Error Detection vs Error Correction
| Error Detection | Error Correction |
|---|---|
| Finds whether an error occurred | Finds and corrects the error |
| Usually needs retransmission | May correct without retransmission |
| Parity, Checksum, CRC | Hamming Code |
Simple idea
Sender
↓
Add extra bits
↓
Transmit
↓
Receiver
↓
Check extra bits
↓
Error?
┌───────┴───────┐
No Yes
↓ ↓
Accept Detect/Correct
2. Parity Bit
Parity is one of the simplest error-detection methods.
A single extra bit called the parity bit is added to the data.
There are two types:
- Even parity
- Odd parity
Even Parity
The total number of 1s, including the parity bit, must be even.
Example
Data:
1011001
Number of 1s = 4
Since 4 is already even:
Data: 1011001
Parity bit: 0
Transmitted: 10110010
Total 1s = 4 → Even
Another example
Data:
1011011
Number of 1s = 5, which is odd.
So we add 1:
1011011 + 1
Total number of 1s = 6 → Even
Odd Parity
The total number of 1s must be odd.
For example:
Data = 1011001
There are 4 ones.
Therefore, parity bit = 1:
10110011
Total 1s = 5 → Odd
Limitation of Parity
Parity can detect many single-bit errors, but it cannot reliably detect errors involving an even number of changed bits.
For example:
Original: 10110010
Received: 10010000
If two bits change, parity may remain unchanged.
Remember:
Parity = Simple + Fast + Error Detection only
3. Checksum
A checksum is an error-detection technique in which data is divided into fixed-size units, these units are added, and the result is used as a checksum.
It is widely associated with networking protocols.
Basic process
Data
↓
Divide into blocks
↓
Add blocks
↓
Generate Checksum
↓
Send Data + Checksum
↓
Receiver calculates again
↓
Compare
Example
Suppose data is divided into four small numbers:
10
20
30
40
Add them:
10 + 20 + 30 + 40 = 100
The sender generates a checksum based on this sum.
The receiver performs the same calculation.
If the calculated result does not agree with the expected checksum relationship:
ERROR DETECTED
If it agrees:
No error detected
In actual Internet checksum calculations, one’s-complement addition and one’s-complement of the sum are used, rather than simply sending the ordinary arithmetic sum.
Advantages of Checksum
- Simple to implement
- Fast
- Requires relatively little computation
- Useful for detecting transmission errors
Disadvantages
- Not as strong as CRC for many types of errors
- Some error patterns can go undetected
- Mainly used for error detection, not correction
Memory:
Checksum = Add the data blocks and use the result to check the data.
4. CRC — Cyclic Redundancy Check
CRC is a powerful and widely used error-detection technique.
It is especially good at detecting burst errors.
CRC is based on binary polynomial division.
Basic idea
Data bits
+
Generator
↓
Binary Division
↓
Remainder
↓
CRC
The remainder is attached to the original data.
CRC Working
Suppose:
Data = 110101
Generator = 1011
If the generator has 4 bits, we append:
4 - 1 = 3 zeros
So:
110101000
Now divide this binary number by the generator:
110101000 ÷ 1011
The remainder becomes the CRC.
The sender transmits:
Original Data + CRC
Receiver Side
The receiver divides the received frame by the same generator.
Received Data + CRC
↓
Divide by G
↓
Remainder
If:
Remainder = 0
→ No error is detected.
If:
Remainder ≠ 0
→ Error detected.
CRC Diagram
SENDER
│
Data bits
│
↓
┌─────────────────┐
│ Binary Division │
│ by Generator G │
└─────────────────┘
│
↓
Remainder
(CRC)
│
↓
Data + CRC
│
Transmission
│
↓
RECEIVER
│
↓
Divide by same G
│
┌─────┴─────┐
↓ ↓
Remainder=0 Non-zero
↓ ↓
Accept Error
Important
CRC generally detects errors; it does not itself correct them.
Advantages
- Very strong error detection
- Excellent for burst errors
- Widely used in computer networks and communication systems
Memory:
CRC = Divide → Remainder → Check
5. Hamming Code
Hamming Code is an error-correction technique.
Unlike parity, checksum and CRC, Hamming Code can not only detect an error but can also identify its position and correct it under its designed error-correction capability.
The basic Hamming code can:
Correct one-bit error.
It can also detect certain multiple-bit error patterns depending on the specific Hamming code and distance used.
How Hamming Code Works
Hamming Code adds special parity bits to the original data.
Suppose the data is:
1011
We need to add parity bits.
For 4 data bits, we need 3 parity bits.
So:
Data bits = 4
Parity bits = 3
Total = 7 bits
This is commonly called Hamming(7,4).
Position of Parity Bits
Parity bits are placed at positions that are powers of 2:
Position:
1 2 3 4 5 6 7
Bit:
P1 P2 D1 P4 D2 D3 D4
Therefore:
P1 → position 1
P2 → position 2
P4 → position 4
Data bits occupy:
3, 5, 6, 7
Why Parity Bits Have Different Positions?
Each parity bit checks a different group of positions.
For Hamming(7,4):
P1 checks:
1, 3, 5, 7
P2 checks:
2, 3, 6, 7
P4 checks:
4, 5, 6, 7
At the receiver, these parity checks produce a pattern called the syndrome.
The syndrome tells us which bit is wrong.
Example of Error Correction
Suppose the sender sends:
1011010
During transmission, one bit changes:
1010010
↑
Error
The receiver performs the parity checks.
Suppose the result indicates:
Syndrome = 4
This means:
Bit position 4 contains the error.
The receiver changes that bit:
Wrong: 1010010
Correct: 1011010
↑
corrected
Thus, Hamming Code can correct the error without asking the sender to retransmit the whole frame.
How Many Parity Bits Are Required?
For m data bits and r parity bits:\[ 2^r \geq m+r+1 \]
Example: 4 data bits
Here:
m = 4
Try:
r = 3
Then:\[ 2^3 = 8 \]
and:\[ m+r+1 = 4+3+1 = 8 \]
Therefore, 3 parity bits are required.
So:
4 data bits + 3 parity bits = 7 bits
Hence:
Hamming(7,4).
6. Comparison of All Four Techniques
| Technique | Main Purpose | Basic Idea | Corrects Error? |
|---|---|---|---|
| Parity | Detection | Add one parity bit | ❌ No |
| Checksum | Detection | Add data blocks and generate checksum | ❌ No |
| CRC | Detection | Polynomial/binary division | ❌ No |
| Hamming Code | Detection + Correction | Multiple parity bits identify error position | ✅ Yes, basic form corrects 1-bit error |
7. Easy Difference to Remember
Think of four security guards:
Parity
“Something is wrong.”
Checksum
“My calculation doesn’t match.”
CRC
“The transmitted pattern doesn’t match the expected remainder.”
Hamming Code
“Error is at bit number 4. I can correct it.”
So:
Parity → Detect
Checksum → Detect
CRC → Detect
Hamming → Detect + Correct
8. Error Detection vs Correction
ERROR CONTROL
│
┌──────────┴──────────┐
↓ ↓
ERROR DETECTION ERROR CORRECTION
│ │
┌─────┼─────┐ │
↓ ↓ ↓ ↓
Parity Checksum CRC Hamming Code
⭐ Exam Summary
Parity
- Adds one parity bit.
- Even or odd parity.
- Simple and fast.
- Detects many single-bit errors.
- Cannot correct errors.
Checksum
- Divides data into blocks.
- Performs arithmetic addition.
- Generates checksum.
- Receiver recalculates and compares.
- Mainly error detection.
CRC
- Uses binary/polynomial division.
- Remainder becomes CRC.
- Receiver divides again.
- Zero remainder → no error detected.
- Non-zero remainder → error detected.
- Very effective for burst errors.
Hamming Code
- Adds multiple parity bits.
- Parity bits placed at positions 1, 2, 4, 8…
- Uses syndrome to locate an erroneous bit.
- Basic Hamming code corrects one-bit errors.
- Formula:
\[ \boxed{2^r \geq m+r+1} \]
One-line memory
Parity = Simple, Checksum = Addition, CRC = Division, Hamming = Correction.
