L
LLLOS.ai
Learn
L

Ask Your Tutor · Computer Science

How does Hamming code work if there are two errors?

From NCERT In depth Asked by Anonymous from Frankfurt, Germany 24 Oct 2026, 7:24 AM IST Updated

In one line

Hamming code can find and fix one error, but if there are two errors, it cannot correct them and may even give the wrong answer.

Richard Hamming — American mathematician and information theorist (1915–1998)
Richard Hamming — American mathematician and information theorist (1915–1998)
Richard Hamming, who invented the Hamming code in 1950 to help computers fix errors automatically.
Image: Wikipedia

The rule

Hamming code is an error-detecting and error-correcting code that can detect up to two errors and correct only one error in a block of data.

The key formula for the number of parity bits (p) needed for a data block of length d: 2^p ≥ d + p + 1

  • p = number of parity bits
  • d = number of data bits

Let's understand it simply

Imagine you are playing cricket and you write down the score after every over. To make sure you don’t make a mistake, you ask your friend to check your writing. If you make one mistake, your friend can spot and fix it. But if you make two mistakes at the same time, your friend might not know which numbers are wrong. Hamming code works like your friend: it can fix one error, but gets confused if there are two.

Think of Hamming code as a safety net for your data. If only one rope breaks (one error), the net can still hold you. But if two ropes break (two errors), you might fall through, or the net might pull you in the wrong direction.

How it works

  1. Adding parity bits: Hamming code adds extra bits (called parity bits) to your data. These bits help check if the data is correct.
  2. Sending data: The data with parity bits is sent over the network or stored somewhere.
  3. Receiving data: When the data is received, the receiver checks the parity bits to see if there is any error.
  4. Finding the error: If there is one error, the parity bits show exactly where it is, so it can be fixed.
  5. Two errors: If two bits are wrong, the parity bits get confused. They might point to a wrong location, or say there is only one error when there are actually two.
  6. Result: Hamming code can tell something is wrong (detects two errors), but cannot fix both. Sometimes, it may not even notice if the errors cancel each other out.
How Hamming Code Handles Errors
  1. Add parity bits to data
  2. Send codeword
  3. Receive codeword
  4. Check parity bits
  5. If one error: find and fix it
  6. If two errors: code gets confused, can't fix both

The story behind it

Richard Hamming, an American mathematician, invented Hamming code in 1950. He worked at Bell Labs, where he was frustrated by computers stopping work because of small errors in punched cards. He wanted a way for computers to fix simple mistakes by themselves, so he created this code. Hamming’s work was one of the first steps toward making computers more reliable.

Where you see it in real life

  • RAM (computer memory): Hamming code is used in some computer memories to catch and fix single-bit errors.
  • Satellite communication: When data is sent far away (like to a satellite), Hamming code helps fix small mistakes caused by noise.
  • Bank ATMs: Some ATM cards use Hamming code to check if the data read from the card is correct.
  • Railway ticket machines: The printed ticket data may use Hamming code to avoid mistakes.
  • Mobile phones: Older mobile networks used Hamming code to protect text messages.
  • Barcode readers: Some barcodes use Hamming code to check for errors in the scanned data.

Why it matters

  • Reliability: Hamming code helps computers find and fix mistakes, making them more reliable.
  • Data safety: It protects important data from being lost or changed by accident.
  • Foundation for advanced codes: Many stronger error-correcting codes are built on Hamming’s ideas.
  • Exams and careers: Understanding Hamming code is important for exams and for jobs in IT, electronics, and communication.

Worked example

Let’s say you use a (7,4) Hamming code (7 bits total: 4 data, 3 parity). You send 1011 as data. The codeword might be 1011010.

Suppose two errors happen: bits 2 and 5 flip.

Original codeword: 1 0 1 1 0 1 0
Error happens:     1 1 1 1 1 1 0
Step 1: Receiver checks parity bits
Step 2: Parity checks point to a position (say, bit 3)
Step 3: But bit 3 is not wrong! Two errors have confused the code
Step 4: If you flip bit 3, the codeword is still wrong
Step 5: Hamming code cannot fix both errors, and may even make it worse

Common mistakes

  • Thinking it can fix two errors: Hamming code can only fix one error, not two.
  • Assuming it always detects two errors: Sometimes, two errors can cancel each other, and the code may not notice.
  • Forgetting to check all parity bits: You must check every parity bit to find the error location.
  • Mixing up detection and correction: Detecting two errors is possible, but correcting two is not.

Remember it

Hamming code: Fixes one error, finds two, but can’t fix both.

Check yourself

Why can't Hamming code correct two errors at the same time?

Because the parity bits only give enough information to fix one error; with two, the information is confused.

What happens if two errors occur in a Hamming code word?

The code may detect an error but cannot fix both, and might even point to the wrong bit.

Where is Hamming code used in real life?

In computer memory (RAM), satellite communication, ATM cards, and barcode readers.

What is the main job of parity bits in Hamming code?

To help find and fix single-bit errors in the data.

Quick recap

  • Hamming code can correct only one error, not two.
  • With two errors, it may point to the wrong bit or miss the error.
  • It is widely used for error correction in computers and communication.
  • Two errors can sometimes go undetected if they cancel each other.
  • Hamming code was invented by Richard Hamming in 1950.

Read it in the NCERT book

Written by the LLOS.ai tutor, checked against NCERT chapters. Asked by Anonymous from Frankfurt, Germany on 24 Oct 2026, 7:24 AM IST