In the last episode (#20), we saw that just one extra bit, the parity bit, can tell us if an error has occurred in the message we send. Building on this idea, mathematician Richard Hamming asked a natural but brilliant question:

Can we not only detect errors, but also correct them just by adding a few extra parity bits?

Before diving in, make sure you’ve read episode #20—this builds directly on that.

So here’s the challenge!

I want to send 4 bits of information. How many extra bits do I need so that one error can be detected and corrected?

Let us try to answer this the hard way.

Step 0: What Does “Correcting an Error” Actually Mean?

Suppose I send this 4-bit message:

1011

If one bit flips, the receiver might see:

1001

or

1010

or something else.

Correcting an error means two things:

  1. The receiver must know that an error happened

  2. The receiver must know which bit is wrong

If we do not know the location, we cannot fix it.

Step 1: Try Adding One Extra Bit

Let us start small.

We add one extra bit, just like last time. The value of this extra bit is 0 or 1 such that the total number of ones in a message is always even.

Total bits sent:
4 data bits + 1 parity bit = 5 bits

This parity bit can tell us:

• Even number of ones → probably fine
• Odd number of ones → something flipped

So yes, we detect the error. But here is the problem. If the parity check fails, which bit flipped?

• Bit 1?
• Bit 2?
• Bit 3?
• Bit 4?
• Bit 5? (the parity bit itself?)

That is 5 possible error locations, and we have only one bit of information coming from the parity check.

One bit can only distinguish between two cases. So one extra bit is not enough.

Step 2: What If We Add Two Extra Bits?

Now let us try again.

4 data bits + 2 parity bits = 6 bits

Let us call the parity check bits A and B. Each parity bit can check a different subset of the message.

At the receiver, we now get two yes/no answers:

• Parity check A: pass or fail
• Parity check B: pass or fail

That gives us four possible outcomes:

00
01
10
11

Four patterns.

But how many things do we need to distinguish?

• Bit 1 flipped
• Bit 2 flipped
• Bit 3 flipped
• Bit 4 flipped
• Parity bit A flipped
• Parity bit B flipped

That is 6 possibilities.

Four patterns are not enough. No matter how cleverly we design the checks, two extra bits cannot uniquely identify the error. So two extra bits still do not work.

Step 3: Try Three Extra Bits

Now things get interesting.

4 data bits + 3 parity bits = 7 bits

At the receiver, we perform three parity checks. Each check either passes or fails.

That gives us:

000
001
010
011
100
101
110
111

Eight possible patterns. So we can include no error case as well!

Now count what we need to identify:

• No error
• Bit 1 flipped
• Bit 2 flipped
• Bit 3 flipped
• Bit 4 flipped
• Parity bit A flipped
• Parity bit B flipped
• Parity bit C flipped

That is 8 distinct cases.

For the first time, the numbers match. Three extra bits are actually enough. But only if we use them very carefully.

The Crucial Insight

We now understand the requirement. Each bit position must produce a unique pattern of parity check failures when it flips.

In other words:

Every bit must be watched by a unique combination of parity checks.

That sentence is the entire Hamming code in disguise. Now we need a way to organize these combinations.

This is exactly where a beautiful picture of overlapping circles (which I shared as a hint last time) enters the story.

Step 4: Build Your First Error Correction Code

Let us now explicitly construct how three extra bits can be used to protect a four bit message. Suppose the message is 1011. We begin by placing these message bits into the overlapping regions of the circles, as shown below.

As you can see, three regions remain unfilled. These are where we place the parity check bits. There is only one rule governing how they are chosen:

Choose the parity bits so that the total number of ones in each circle is EVEN.

Filling in the parity bits according to the rule above gives us the following picture (for clarity, parity bits are highlighted in green):

Since the original message is 1011 and the parity bits are 010, the complete message that we send is:

1011010

Step 5: Error Detection and Correction

Now imagine that one of the bits is flipped and we must figure out which one. If the second bit is flipped, the result is:

1111010

This can also be visualised in the diagram like below:

To check for errors and identify if any bit has been flipped, we follow the same procedure as before: verify that each parity bit (highlighted in green) ensures the total number of ones in its circle is even.

Let’s examine them one by one.

  • Blue circle: There are three ones, so the green parity bit should be 1, but it is 0. Something is wrong.

  • Orange circle: There are three ones, so the parity bit should be 1, and it is. This one is correct.

  • Purple circle: Again, there are three ones, so the parity bit should be 1, but it is 0. Another error!

We have detected two parity failures: the blue and the purple circles.

Which bit actually flipped? It’s simple: the flipped bit is the one common to both the blue and purple circles. That is the culprit! To correct the error, we simply flip the bit back to its correct value.

What happens if one of the parity bit itself (green ones) get flipped? Try it yourself!

Hooray! Using just three extra bits, we can now send four bits of information while protecting against a single error. This is also called the Hamming [7, 4] code.

Conclusion and Bonus

Notice why this is so cool. Using the repetition code from last episode, sending 4 bits of information would need 3 copies — that’s 12 bits! Now, with this clever arrangement, we only used 7 bits. That’s a 40% reduction in the number of bits sent.

The key idea is simple but powerful: we carefully arranged who checks whom. That structure alone tells us exactly where an error happens.

If you’ve ever wondered how scientists and engineers arrive at elegant solutions to extraordinary problems, you should read The Art of Doing Science and Engineering by Richard Hamming. Just click below!

It’s not just about the math—it’s about the mindset that drives breakthroughs in science and engineering.

Endorsement (not paid):

In today’s world, having a personal website is becoming as important as having a résumé. For students and professionals alike, it provides a clear, reliable place to showcase your work, skills, and portfolio. If you already don’t have one, do check this:

Keep Reading