L
LLLOS.ai
Learn
L

Ask Your Tutor · Computer Science

How does Hamming code find which bit is wrong?

From NCERT In depth Asked by Anonymous from Dallas, United States 24 Oct 2026, 3:09 AM IST Updated

In one line

Hamming code checks special bits to find and fix exactly which bit in a message is wrong.

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 uses extra bits (called parity bits) to locate and fix a single wrong bit in a block of data.

The main formula for placing parity bits: Positions of parity bits: 2⁰, 2¹, 2², ... (1, 2, 4, 8, ...) Each parity bit checks certain positions in the data.

The formula
Positions: 2⁰, 2¹, 2², ...
2⁰, 2¹, 2², ...positions of parity bits (1, 2, 4, 8, ...)

Let's understand it simply

Imagine you are sending a message to your friend, but some letters might get smudged on the way. Hamming code is like adding secret checkers (parity bits) in your message. These checkers look at different parts of your message. If one letter gets smudged, the checkers can work together to point out exactly which letter is wrong.

Think of a cricket team where each coach watches a few players. If a player makes a mistake, the coaches who notice it can tell you exactly who it was. Hamming code does the same with bits in your data.

How it works

  1. Add parity bits: Insert parity bits at positions 1, 2, 4, 8, etc. in your data.
  2. Set parity bits: Each parity bit checks a group of bits (including itself) and is set so the total number of 1s in that group is even (or odd, depending on the rule).
  3. Send the data: The full message (data + parity bits) is sent.
  4. Check parity at receiver: The receiver recalculates the parity for each group.
  5. Find the error: If a group’s parity is wrong, note the parity bit’s position. Add up all the wrong parity positions. The sum tells you the exact bit that is wrong.
  6. Fix the error: Flip (change) that bit to correct the message.
How Hamming Code Finds the Wrong Bit
  1. Insert parity bits at positions 1, 2, 4, 8...
  2. Set each parity bit to make its group even (or odd)
  3. Send the message
  4. Receiver checks each parity group
  5. Add up positions of wrong parities to find the error bit
  6. Flip that bit to fix the message

The story behind it

Richard Hamming, an American mathematician, invented the Hamming code in 1950. He worked at Bell Labs, where computers would stop working if even one bit was wrong. Hamming wanted a way for computers to fix small mistakes by themselves, instead of waiting for a person to restart the job. His idea made computers much more reliable.

Where you see it in real life

  • RAM in computers: Hamming code helps your computer memory fix small errors automatically.
  • Satellite communication: When signals travel far, bits can flip. Hamming code helps spot and fix them.
  • Bank ATMs: Checks for errors in the data sent between machines and banks.
  • Mobile phones: Keeps your messages and calls clear by correcting small errors.
  • Barcode readers: Fixes small mistakes when scanning products in shops.
  • CDs and DVDs: Repairs tiny scratches by correcting the data read from the disc.

Why it matters

  • Reliability: Makes sure computers, phones, and machines work smoothly even if a small error happens.
  • Safety: Prevents wrong data from causing problems in banking, medicine, or transport.
  • Foundation for more codes: Hamming code is the base for more advanced error-correcting codes.
  • Exam questions: Often asked in computer science exams, especially about error correction.

Worked example

Let’s say you want to send 4 bits: 1 0 1 1

Add parity bits at positions 1, 2, and 4:

Step 1: Arrange bits with spaces for parity bits: _ _ 1 _ 0 1 1
           (positions: 1 2 3 4 5 6 7)
Step 2: Place data bits: _ _ 1 _ 0 1 1
Step 3: Calculate parity bits:
    - Parity bit 1 (position 1): checks bits 1,3,5,7 (positions 1,3,5,7)
      Bits: _ 1 0 1 → 1+0+1 = 2 (even), so parity bit 1 = 0
    - Parity bit 2 (position 2): checks bits 2,3,6,7 (positions 2,3,6,7)
      Bits: _ 1 1 1 → 1+1+1 = 3 (odd), so parity bit 2 = 1
    - Parity bit 4 (position 4): checks bits 4,5,6,7 (positions 4,5,6,7)
      Bits: _ 0 1 1 → 0+1+1 = 2 (even), so parity bit 4 = 0
Step 4: Final code: 0 1 1 0 0 1 1
Step 5: Suppose bit 6 flips (should be 1, but is 0): 0 1 1 0 0 0 1
Step 6: Receiver checks parity:
    - Parity 1: positions 1,3,5,7 → 0 1 0 1 = 2 (even) → OK
    - Parity 2: positions 2,3,6,7 → 1 1 0 1 = 2 (even) → OK
    - Parity 4: positions 4,5,6,7 → 0 0 0 1 = 1 (odd) → Error in parity 4
Step 7: Only parity 4 is wrong (position 4). So, bit 6 is wrong (since 4+2=6, but only 4 is wrong, so position 6).
Step 8: Flip bit 6 back to 1. Message is fixed!

Common mistakes

  • Forgetting parity bit positions: Parity bits go at 1, 2, 4, 8, not just anywhere.
  • Wrong parity calculation: Always check which bits each parity covers (use a table or draw it).
  • Not adding up error positions correctly: Add the positions of wrong parity bits to find the error.
  • Thinking it fixes all errors: Hamming code can only fix one wrong bit at a time, not more.

Remember it

Hamming code’s parity bits are like secret detectives—together, they point to the exact bit that’s wrong.

Check yourself

Where are the parity bits placed in Hamming code?

At positions 1, 2, 4, 8, etc. (powers of 2), because each checks a different group of bits.

Why does Hamming code add up the positions of wrong parity bits?

Because the sum tells you the exact bit that is wrong.

Can Hamming code fix two errors at once? Why or why not?

No, it can only fix one error at a time because it is designed to find and correct a single wrong bit.

Give one real-life place where Hamming code is used.

In computer RAM, to fix small errors in memory automatically.

Quick recap

  • Hamming code uses special parity bits to find and fix one wrong bit.
  • Parity bits are placed at positions 1, 2, 4, 8, etc.
  • Each parity bit checks a unique group of bits.
  • Adding the positions of wrong parities shows the exact error bit.
  • It is used in computers, phones, and CDs to correct small errors.
Written by the LLOS.ai tutor, checked against NCERT chapters. Asked by Anonymous from Dallas, United States on 24 Oct 2026, 3:09 AM IST