Hamming code calculator
A Hamming code is an error-correcting code that adds a few carefully placed parity bits to a block of data so the receiver can not only detect a single-bit error but pinpoint and fix it. The classic Hamming (7,4) code takes four data bits and produces a seven-bit codeword by inserting three parity bits at the power-of-two positions 1, 2 and 4. This calculator encodes four data bits that you enter, in the order d1 d2 d3 d4, into the full seven-bit codeword and shows each parity bit. Parity bit p1 covers positions 1, 3, 5 and 7; p2 covers positions 2, 3, 6 and 7; and p4 covers positions 4, 5, 6 and 7. Each parity bit is set so that the count of ones in the positions it covers is even. Because every data bit is covered by a unique combination of parity bits, a single flipped bit anywhere in the codeword reveals exactly which bit went wrong. Enter your own four data bits to build a codeword or check a coding-theory exercise. Every figure here is computed deterministically from the standard Hamming (7,4) rules, shown in full below with a worked example that reconciles exactly to the calculator.
Hamming (7,4) encodes four data bits into a seven-bit word p1 p2 d1 p4 d2 d3 d4, choosing each parity for even parity over its positions. For data bits 1011 the codeword is 0110011, with parity bits p1 = 0, p2 = 1, p4 = 0.
Hamming (7,4) encoding
codeword positions: 1=p1, 2=p2, 3=d1, 4=p4, 5=d2, 6=d3, 7=d4
p1 = d1 XOR d2 XOR d4 (covers positions 1,3,5,7)
p2 = d1 XOR d3 XOR d4 (covers positions 2,3,6,7)
p4 = d2 XOR d3 XOR d4 (covers positions 4,5,6,7)
each parity makes the ones in its positions even
Parity bits sit at the power-of-two positions 1, 2 and 4, and data bits fill the rest. Each parity bit is the XOR of the data bits it covers, set so that its group has an even number of ones. This lets a single error be located and corrected.
Worked example
Encode the four data bits d1 d2 d3 d4 = 1 0 1 1 into a Hamming (7,4) codeword.
- p1 = d1 XOR d2 XOR d4 = 1 XOR 0 XOR 1 = 0
- p2 = d1 XOR d3 XOR d4 = 1 XOR 1 XOR 1 = 1
- p4 = d2 XOR d3 XOR d4 = 0 XOR 1 XOR 1 = 0
- Lay out p1 p2 d1 p4 d2 d3 d4 = 0 1 1 0 0 1 1
- Codeword = 0110011
The data 1011 encodes to the codeword 0110011. These are the calculator's default inputs, so the result above matches the widget exactly.
Hamming code calculator: frequently asked questions
What is a Hamming code?
A Hamming code is a family of error-correcting codes that add parity bits to data so a receiver can detect and correct a single-bit error. The Hamming (7,4) code adds three parity bits to four data bits, giving a seven-bit codeword that can fix any one flipped bit.
Where do the parity bits go?
In the Hamming (7,4) code the parity bits occupy the power-of-two positions 1, 2 and 4, and the data bits fill positions 3, 5, 6 and 7. Placing parity at power-of-two positions means each data position is covered by a unique set of parity bits, which is what makes error location possible.
How does it correct an error?
Each parity bit checks a specific group of positions. If a single bit flips, the parity checks that include it will fail, and the binary pattern of which checks fail points directly to the position of the error. Flipping that one bit back restores the original data.
What does (7,4) mean?
The notation (7,4) means a codeword is 7 bits long and carries 4 bits of actual data, with the other 3 bits being parity. The code rate is therefore four-sevenths. Adding more parity bits lets longer blocks be protected, but (7,4) is the classic single-error-correcting example.
Can it correct more than one error?
The basic Hamming (7,4) code corrects exactly one bit error per codeword and can detect, but not correct, some two-bit errors when extended with an overall parity bit. For multiple errors you need stronger codes. The encoding here is deterministic and reconciles exactly to the worked example.
Official sources
- Coding theory and reference algorithm definitions: US National Institute of Standards and Technology (NIST). As at 25 June 2026.
Reviewed by the CalculatorHub team, edited by James Graham, 25 June 2026. See our methodology. This is general information, not financial, tax, legal or investment advice.