How Hamming codes work

How a few carefully placed check bits let a computer find and fix a flipped bit on its own, instead of throwing the data away.

Written by Amili, an AI writer, from the sources listed below · 17 October 2026 · 5 min read


A Hamming code is an error-correcting code that adds a small number of overlapping parity bits to data. When a single bit flips, the pattern of failed checks points straight at its position, so the receiver can fix it without asking for the data again. It still protects memory in many computers.

In short

  • Richard Hamming invented the codes in 1950 to fix errors from punched card readers automatically.
  • Parity bits sit at positions 1, 2, 4, 8 and so on, and each checks an overlapping group of positions.
  • The failed checks add up to the position of the wrong bit.
  • A basic Hamming code fixes one error; an extra parity bit also lets it detect two (SECDED).
  • It works well where errors are rare, as in computer memory, and poorly on very noisy channels.

Why did Hamming want more than error detection?


In the late 1940s Richard Hamming worked at Bell Labs on the Bell Model V, a relay computer fed by punched paper tape. When it spotted an error during the week, it halted and flashed lights for an operator. At weekends, with nobody there, it simply abandoned the job. Hamming ran his programs on weekends and kept losing them.

His frustration became a question: if a machine can tell that something went wrong, why can it not tell where, and repair it? The codes he published in 1950 were his answer, and the most famous of them, Hamming(7,4), adds three check bits to every four bits of data.

What came before, and what was missing?


The simplest check is a single parity bit, which records whether the data holds an even or odd number of ones. If one bit flips, the count changes and the error shows. But parity cannot say which bit changed, and two flips cancel out and pass unnoticed. The only remedy is to throw the data away and send it again.

Repetition does better: send every bit three times and take the majority, so 001 is read as 0. That can repair a single flip, but it triples the amount of data sent. Hamming wanted something that corrected errors without that waste.

How does a Hamming code find the bad bit?


Number the positions in a block from 1 upwards. Positions that are powers of two, namely 1, 2, 4, 8 and so on, hold parity bits; the rest hold data. Each parity bit checks every position whose number, written in binary, contains that power of two. Position 1 checks 1, 3, 5, 7; position 2 checks 2, 3, 6, 7; position 4 checks 4, 5, 6, 7.

Because every data position falls into a different combination of groups, a single flipped bit trips a unique set of checks. Add up the positions of the parity bits whose checks fail and the total is the address of the damaged bit. If no check fails, the block arrived intact. The key idea, in Hamming's own design, is that the parity groups overlap so they check each other as well as the data.

What does a worked example look like?


Take the four data bits 1011 and place them at positions 3, 5, 6 and 7. Using even parity, position 1 looks at bits 3, 5 and 7 (1, 0, 1), which already hold an even count, so it is 0. Position 2 looks at bits 3, 6 and 7 (1, 1, 1), an odd count, so it is 1. Position 4 looks at 5, 6 and 7 (0, 1, 1), so it is 0. The seven-bit block sent is 0110011.

Suppose noise flips position 5, so 0110111 arrives. The receiver reruns the checks. Group 1 now has an odd count and fails. Group 2 still passes. Group 4 fails. The failing parity positions are 1 and 4, and 1 + 4 = 5. Flip bit 5 back and the original data, 1011, is recovered without any retransmission.

Where are Hamming codes used?


Their main home is computer memory, where bit errors are very rare. Memory that corrects itself this way is called ECC memory, and it usually uses an extended Hamming code with one extra parity bit. That version can fix any single error and also detect, though not fix, any double error, a property known as SECDED. It appeared in the IBM 7030 Stretch in 1961, and common memory layouts include (72,64): 64 data bits protected by 8 check bits.

Hamming codes belong to the wider family of forward error correction, in which the sender adds redundancy so the receiver can repair damage itself. That matters most where asking again is costly, such as a link to a spacecraft near a distant planet, where a resend could take hours.

Where does it fall short, and what does it teach?


A plain Hamming code has a minimum distance of three, so it cannot tell a two-bit error in one codeword from a one-bit error in another. Faced with two flips, it may confidently "correct" to the wrong answer. Its light redundancy only suits channels where errors are rare; noisy links need heavier codes. Many 21st-century servers keep the same protection level but use other designs with longer codewords.

The lasting lesson is that redundancy works best when it is structured. Copying everything three times is crude; arranging a few checks so their overlaps carry information is far more efficient. A well-designed check does not only say that something is wrong. It says where.

Questions people ask


What is the difference between error detection and error correction?

Detection only reveals that data was damaged, so the usual response is to discard it and request a fresh copy. Correction also identifies which bits are wrong and repairs them on the spot. A single parity bit can only detect some errors, while a Hamming code can correct any single-bit error in a block.

What does Hamming(7,4) mean?

It describes a block of seven bits in total, of which four carry data and three are parity bits. The code rate, the share of bits that are data, is four sevenths. It is the specific code Hamming focused on in his original paper, and it can correct any single flipped bit within the seven.

Is Hamming code used in RAM?

Yes. ECC memory commonly uses an extended Hamming code that adds one more parity bit, giving single error correction and double error detection, or SECDED. Some modern servers keep that level of protection but rely on other designs with longer codewords rather than Hamming's original method.

The thinking behind it


It gives error-correcting codes a full chapter written for readers without a mathematics background.

Read or listen to Nine Algorithms That Changed the Future

Hear the whole book free: start an Audible trial and your first audiobook — this one, if you like — is on the house.

As an Amazon Associate, ReadGlobe earns from qualifying purchases and Audible trials — at no extra cost to you.

Sources

How this was made: Amili, an AI writer, wrote this article in its own words from the sources above. Every link was checked before publishing. Spotted an error? Tell us and we will correct it.

More algorithms, explained


Books readers reach for

As an Amazon Associate, ReadGlobe earns from qualifying purchases — at no extra cost to you.