← Cryptography guide

K104 / Encoding and decoding

Hamming code

Hamming code · Survey date 2026-12-05

Hamming codes are a family of linear error-correcting codes that append parity to data to correct errors.

CRYPTOGRAPHY LAB / K104

Cryptography Lab · Hamming code

Run real computations and inspect intermediate states step by step.

Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.

Scope: Standard operation

Hamming (7,4)

See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.

Open lab →

Definition and overview
Hamming codes are a family of linear error-correcting codes that append parity to data to correct errors. Source document ↗
Classification and reversibility
Error-correcting encoding whose decoder can restore the original message vector from a codeword. Source document ↗
Key or secret requirements
Not confirmed in the survey
Operating principle and structure
Splits messages into k-bit blocks and adds n−k parity bits to form n-bit codewords. Source document ↗
Key size, block size and parameters
Typical (7,4): four data bits, three parity bits, seven-bit codeword. Source document ↗
Security strength and recommendation
Not confirmed in the survey
Known attacks and vulnerabilities
Not confirmed in the survey
Standards and certification
Not confirmed in the survey
Typical uses
Error-correction encoding in computer science and communications. Source document ↗
Implementations, libraries and tools
Python/C++ packages such as hamming-codec. Source document ↗
Decryption or decoding
Multiply the received codeword by parity-check matrix H to obtain syndrome; locate and correct the error. Source document ↗
Advantages
Efficient parity use; a perfect code attaining the highest rate for its block length and minimum distance 3. Source document ↗
Limitations and cautions
Limited to single-bit correction and one/two-bit detection; undetected errors may occur. Source document ↗
Distinguishing encryption, encoding and hashing
Error-correcting encoding, not encryption or hashing. Source document ↗

Practical examples

Examples are illustrative; they are not execution-tested implementations or operational recommendations.

Example

Compute three parity bits for four data bits and transmit a seven-bit codeword. Receiver computes syndrome: if zero, extract data bits; if nonzero, correct the indicated bit then restore data. No secret key.

Procedure

Encode by dividing into k-bit blocks, computing n−k parity bits and forming/transmitting codewords. Decode using parity checks/syndromes, error location/correction and data extraction. Unlike keyed encryption, Hamming uses public error-correction rules.

Scenario

Use in memory ECC, forward error correction in wireless/satellite communications and educational simulations. Add encryption separately if confidentiality is needed.

Pitfalls and alternatives

Not encryption or hashing. Weak against multi-bit/burst errors; combine with SECDED, CRC or FEC/ECC or choose an appropriate alternative. HQC (Hamming Quasi-Cyclic) is a separate code-based KEM, not Hamming coding.

References