Bits go wrong
Send four data bits, 1011, over a noisy link. Noise (random voltage added on the way) can push a bit past the receiver's cut-off between 0 and 1, so a 0 arrives as a 1. The receiver gets 1111 and cannot tell.
Add one parity bit P so the count of 1s is even: 1011 has 3 ones, so P = 1. One flip makes the count odd, and the receiver knows something broke. It cannot tell which bit, and two flips cancel out.
Building a Hamming code
Hamming's idea (1950): use three parity bits, each over a different, overlapping group. Number seven slots 1 to 7. The parity bits go in slots 1, 2 and 4 (powers of two); the data 1011 fills slots 3, 5, 6 and 7.
Parity bit p1 makes its group even. Its group is every odd slot: 1, 3, 5 and 7. The data there is 1, 0 and 1: two ones, already even, so p1 = 0.
p2 covers slots 2, 3, 6 and 7 (their numbers have the 2s bit set). The data there is 1, 1 and 1: three ones, an odd count, so p2 = 1 to make it even.
p4 covers slots 4 to 7. The data there is 0, 1 and 1: even, so p4 = 0. The codeword is 0110011. Seven bits now carry four: the code rate is 4/7 ≈ 0.571.
Finding and fixing
All seven bits go out. Noise flips slot 5 again, a data bit this time hidden among parity bits. The receiver holds 0110111, one bit away from what was sent.
The receiver recounts each group. Group 1 is odd: fail. Group 2 is even: pass. Group 4 is odd: fail. Add the failing group numbers: 1 + 4 = 5. That pattern, 101 in binary, is called the syndrome.
Flip slot 5 back: 0110111 becomes 0110011, the word that was sent. Read the data from slots 3, 5, 6 and 7: 1011. The error was found and fixed with no resend.
Limits and code
If each bit flips 1 time in 100, four bare bits arrive wrong 3.9% of the time; Hamming(7,4) fails only when two or more of its seven flip: 0.20%. Two flips fool it: it fixes the wrong slot.
In Python with numpy, each row of a matrix H marks one group. H @ r % 2 counts each group's ones and keeps odd or even: the syndrome. Wi-Fi 6 and 5G use far longer low-density parity-check (LDPC) codes built on this idea.
The working
# step 1/11 · flip sent 1011 noise flips one bit (slot 5 here) received 1111 1111 is also a valid message, so nothing looks wrong. why bits flip: the AWGN lesson (noise + picking the nearest level)
The data 1011, the flipped slot 5 and the flip chance 1 in 100 are chosen examples. Every bit, check and percentage in the figure is computed from this model. The percentages assume each bit flips on its own with the same chance p (a binary symmetric channel). Real links also suffer bursts of errors in a row; the CRC lesson handles those.