Electrical engineering

Hamming code

Any of a family of linear error-correcting codes that generalize the Hamming(7,4)-code invented by Richard Hamming in 1950.

Hamming code: error detection baked into data itself

A Hamming code is a method of encoding data with extra bits so that single-bit errors can be detected and corrected automatically. The most common practical variant, Hamming(7,4), takes 4 bits of actual data and adds 3 parity bits, producing a 7-bit codeword. When that 7-bit block travels through noisy electronics or storage, any single bit flip can be located precisely by the receiver and flipped back to its original state, all without asking for retransmission.

The elegance of Hamming codes lies in their systematic structure. Each parity bit covers a specific subset of the data bits, positioned at powers of two (positions 1, 2, 4 in a 7-bit word). By checking which parity bits fail, the decoder calculates a binary address pointing directly to the flipped bit. This is why Hamming(7,4) can correct any single error in a 7-bit block: the three parity bits create 2^3 = 8 possible syndrome values, enough to identify any one of seven positions plus a no-error state.

Extended Hamming codes add one more parity bit across the entire codeword, enabling detection (but not correction) of double-bit errors. Hamming(8,4) is the extended version of Hamming(7,4). Larger variants like Hamming(15,11) and Hamming(31,26) pack more data bits with the same correction capability, improving efficiency; they follow the pattern that any Hamming(2^m - 1, 2^m - m - 1) code can correct single errors using m parity bits.

Hamming codes see practical use in early computer memory (single-bit error correction in DRAM was common in older systems), telecommunications equipment, and embedded systems where computational overhead for decoding is minimal. They fall short for high-noise channels where multi-bit errors dominate, giving way to more robust families like Reed-Solomon or LDPC codes. For storage and short-distance links with low error rates, however, Hamming codes remain efficient because their overhead is modest and decoding is fast.

The trade-off is rigid: correction power is locked to code length. You cannot simply add more parity bits to a Hamming(7,4) to correct double errors; you must switch to a different family. This limits flexibility in adapting to changing channel conditions. Modern applications often prefer turbo codes or convolutional codes for their adaptability, but Hamming codes remain the pedagogical touchstone for error correction and continue to appear in legacy systems and safety-critical embedded designs where simplicity and predictability matter.

More from Electrical engineering

See all

Get the Word of the Day

One industrial term every weekday, with the trade it belongs to and why it is worth knowing. No advertising.