Encode data using Hamming code for error detection and correction.This is an encoder only. Full error correction requires syndrome decoding on the receiver side (not included).
Last updated: March 2026 | By Patchworkr Team
Hamming code is a linear error-correcting code named after Richard Hamming. It adds parity bits to data bits to detect and correct single-bit errors in transmitted or stored data. This makes it invaluable in computer memory (ECC RAM), telecommunications, and data storage systems.
The code works by placing parity bits at positions that are powers of 2 (positions 1, 2, 4, 8, 16, etc.). Each parity bit checks specific data bit positions, creating an overlapping pattern that allows pinpointing and correcting errors. The minimum number of parity bits required is determined by the formula: 2^r ≥ m + r + 1, where m is the number of data bits and r is the number of parity bits.
Hamming code can detect up to two-bit errors and correct single-bit errors automatically. Extended Hamming codes can detect (but not correct) two-bit errors by adding one more parity bit. This makes it particularly useful in situations where retransmission is costly or impossible, such as deep space communication or memory systems.
Hamming code encoding follows these systematic steps:
Each parity bit covers specific positions:
Let's encode the data bits "1011":
Standard Hamming code can detect up to 2-bit errors and correct 1-bit errors. SECDED (Single Error Correction, Double Error Detection) Hamming codes add an extra parity bit to detect 2-bit errors without correcting them.
Powers of 2 create a binary pattern where each parity bit's position number represents which bit positions it checks. This elegant system allows the error position to be calculated directly from which parity checks fail.
Simple parity can only detect errors, not locate or correct them. Hamming code uses multiple parity bits in a structured pattern that not only detects errors but also identifies exactly which bit is wrong, allowing automatic correction.
Hamming code is widely used in ECC (Error-Correcting Code) RAM, hard drives, network transmission protocols, satellite communications, QR codes, and any system where data integrity is critical and retransmission is expensive or impossible.
The overhead decreases as data size increases. For 4 data bits you need 3 parity bits (43% overhead), but for 64 data bits you only need 7 parity bits (11% overhead). The formula is 2^r ≥ m + r + 1.
Standard Hamming code cannot effectively handle burst errors (multiple consecutive bits flipped). Interleaving or Reed-Solomon codes are better suited for burst error correction in situations like scratched CDs or corrupted data blocks.
Extended Hamming code adds one extra parity bit that covers all positions. This allows detection (but not correction) of 2-bit errors. The standard Hamming(7,4) becomes extended Hamming(8,4) with this addition.
Error detection and correction with Hamming code is very fast, requiring only a few XOR operations. This makes it suitable for real-time systems and high-speed memory where latency must be minimal.
Related Tools