On this page
In 1950 Richard Hamming of Bell Telephone Laboratories published Error Detecting and Error Correcting Codes in the Bell System Technical Journal. According to the history of the Hamming code, he had been running programs over weekends on the Bell Model V, a relay computer. With no operators on duty, a detected error meant the machine dropped his job and moved on, and he had to restart from scratch. His paper focused on the (7,4) code: send 7 bits to carry 4.
What is the Hamming (7,4) code?
The Hamming (7,4) code turns 4 data bits into a 7-bit codeword by adding 3 parity bits. A parity bit is chosen so that the group of bits it guards contains an even number of 1s.
The bits sit in positions 1 to 7 in the order p1 p2 d1 p3 d2 d3 d4, so the parity bits occupy positions 1, 2 and 4, the powers of two. Each parity bit watches a different group:
p1 checks positions 1, 3, 5, 7 (it guards d1, d2, d4)
p2 checks positions 2, 3, 6, 7 (it guards d1, d3, d4)
p3 checks positions 4, 5, 6, 7 (it guards d2, d3, d4)
The minimum Hamming distance between any two valid codewords is 3, which is why the code can correct any single-bit error (Hamming (7,4)). Its rate is 4/7: about 57% of the transmitted bits are data.
How does the Venn diagram picture work?
Draw three overlapping circles, one per parity bit. Put d4 in the centre, where all three overlap. Put d1, d2 and d3 in the three places where exactly two circles overlap, and each parity bit in the part of its circle that overlaps nothing. The Hamming (7,4) page shows the same picture.
The rule is now visual: every circle must contain an even number of 1s.
How do you encode 1011, step by step?
Take d1 = 1, d2 = 0, d3 = 1, d4 = 1.
p1 = d1 + d2 + d4 = 1 + 0 + 1 = 0 (mod 2)
p2 = d1 + d3 + d4 = 1 + 1 + 1 = 1 (mod 2)
p3 = d2 + d3 + d4 = 0 + 1 + 1 = 0 (mod 2)
Write them in order p1 p2 d1 p3 d2 d3 d4: the codeword is 0110011.
This matches the worked example on the Hamming (7,4) page. Check it on the Venn diagram: the p1 circle holds 0, 1, 0, 1, the p2 circle 1, 1, 1, 1, the p3 circle 0, 0, 1, 1. All even.
How does the syndrome find the flipped bit?
The parity-check matrix H has three rows, one per check, and seven columns. Its rows are 1010101, 0110011 and 0001111 (Hamming (7,4)). Read down any column and you get that column's position number written in binary, with the top row as the ones digit. Column 5 reads 1, 0, 1, which is 101 in binary, or 5.
Suppose noise flips position 5 (d2) and you receive 0110111. Multiplying H by it, mod 2, redoes each parity check:
Check 1, positions 1, 3, 5, 7: 0 + 1 + 1 + 1 = 1. Fails.
Check 2, positions 2, 3, 6, 7: 1 + 1 + 1 + 1 = 0. Passes.
Check 3, positions 4, 5, 6, 7: 0 + 1 + 1 + 1 = 1. Fails.
Read the results as check 3, check 2, check 1: 101, which is 5. Flip position 5 back to get 0110011, and positions 3, 5, 6, 7 give 1011. This three-bit result is the syndrome. It depends only on which bit went wrong, not on the message, because a flip at position j adds column j of H to the result. A syndrome of 000 means accept as received.
Why is 7 = 2³ − 1?
Three checks give 2³ = 8 possible syndromes. One, 000, must mean no error, leaving exactly 7: one per position. With r parity bits the same counting gives block length 2^r − 1 and 2^r − r − 1 data bits, so r = 3 gives (7,4) and r = 4 gives (15,11) (Hamming code).
The count is exact. Each of the 2⁴ = 16 codewords plus its 7 single-flip neighbours covers 8 strings, and 16 × 8 = 128 = 2⁷, so every 7-bit string is a codeword or one flip from exactly one. Codes with this property are called perfect, and Hamming codes are perfect codes (Hamming code).
The limit is the price. If two bits flip, the syndrome is the sum of two columns of H, which is a third column, so the decoder flips a bit that was right and the result is wrong (Hamming (7,4)). Adding an eighth overall parity bit gives the extended code, which corrects one error and detects two (Hamming code).
How should you practise it?
Encode 0000, 1111 and 0101 yourself and check each circle is even.
Flip each of the 7 positions of 0110011 in turn and confirm the syndrome counts 1 to 7.
Flip two bits and see the decoder go wrong.
Next, read Shannon entropy and why a fair coin carries 1 bit, then the binary reflected Gray code and de Bruijn sequences, two more ways of arranging bits with a purpose. If matrices or binary arithmetic are the shaky part, the Fermi Concept Library gives each concept its own lesson and its place in the map.



