Hamming Code Calculator - Encode, Correct, and Decode

Hamming code calculator that encodes binary data into Hamming codewords, detects and corrects single-bit errors using the syndrome, and decodes back to data.

Updated: June 19, 2026 • Free Tool

Hamming Code Calculator

Total bits minus data bits. 7-4 uses 3 parity bits for 4 data bits, 15-11 uses 4 parity bits for 11 data bits, and so on. The default 7-4 is the most common Hamming code.

Encode adds parity bits to the message. Error-correct detects and fixes a single-bit flip in a received codeword. Decode strips the parity bits back to the original data.

Type or paste a binary string of 0s and 1s. For Encode the length must be a multiple of the data-bit count; for Error-correct and Decode the length must be a multiple of the total-bit count. Spaces and a leading 0b are stripped.

Results

Primary Output
0
Syndrome 0
Error Position 0
Status 0

What Is the Hamming Code Calculator?

A Hamming code calculator encodes a binary data word into a Hamming codeword, detects a single-bit flip using the syndrome, and decodes the corrected word back to the original data.

  • Encoding a message before transmission: Add the parity bits so the receiver can detect and fix a single-bit flip without retransmission.
  • Correcting a single-bit flip in a received codeword: Run the received word through the parity-check matrix, flip the bit at the syndrome position, and read the corrected codeword.
  • Decoding a corrected codeword back to data: Strip the parity bits to recover the original data.
  • Teaching the Hamming family: Show students how G and H combine using the Hamming(7,4) textbook example.

The default Hamming(7,4) is the textbook example. The same matrix form extends to Hamming(15,11), Hamming(31,26), Hamming(127,120), and Hamming(255,247), and any single-bit flip in those codewords produces a unique syndrome.

Hamming codes extend single-bit parity into the minimum-distance-3 regime. One parity bit catches an odd number of flips but cannot name which bit; Hamming codes replace it with several parity bits arranged so every single-bit flip is identifiable.

The same parity idea that lets a single parity bit catch any odd number of bit flips is what the Even Parity Calculator uses for one-bit detection, and Hamming codes take the next step by replacing one parity bit with several parity bits so every single-bit flip is identifiable.

How the Hamming Code Calculator Works

The calculator runs the three coding-theory steps. Encode builds the parity bits from the data positions, error-correct multiplies the received codeword by H to read a syndrome, and decode strips the parity bits back to data.

encoded = data with parity bits p where p[j] = sum of ((dataPos[i] >> (r-1-j)) & 1) * data[i] mod 2; syndrome = received * H^T mod 2; error_position = integer(syndrome); corrected = received with bit at error_position flipped; decoded = corrected[1..k]
  • codeSize: Hamming family selector. Sets r, n = 2^r - 1, and k = n - r.
  • process: Encode builds the codeword. Error-correct runs the parity-check matrix and flips the syndrome bit. Decode strips the parity bits back to data.
  • message: Binary string of 0 and 1. Length must be a multiple of k for encode, or a multiple of n for error-correct and decode.
  • primaryOutput: Encoded codeword in encode mode, corrected codeword in error-correct mode, or decoded data bits in decode mode.

Encode is the sender side: parity bits at positions k+1 through n are set so the parity-check matrix returns the zero vector. The receiver multiplies the received codeword by H modulo 2 to read the syndrome, and the same matrix form works for every Hamming family member from 3-1 up to 255-247.

Encode data [1,0,1,1] with Hamming(7,4)

7-4, encode, message 1011

Data bits fill positions 1-4. Parity bits fill positions 5, 6, 7. Parity = 010. Codeword: 1011010.

Primary output: 1011010. Status: Encoded 1 block of 4 data bits into Hamming(7,4).

The 4-bit data word becomes a 7-bit codeword with three parity bits. The receiver can run the same codeword through the parity-check matrix to flag any single-bit flip.

Correct a single-bit flip in a Hamming(7,4) codeword

7-4, error-correct, message 1001010 (bit 3 of 1011010 flipped)

received = [1,0,0,1,0,1,0]. Syndrome = (0,1,1) = binary 3. Flip bit 3 back: corrected = 1011010.

Primary output: 1011010. Syndrome: 011. Error position: 3. Status: Corrected 1 single-bit error at position 3.

The parity-check matrix turns the flipped-bit position into a unique syndrome, so the receiver fixes any single-bit error with no retransmission.

According to Omni Calculator, encoding the data word 1011 with Hamming(7,4) returns the codeword 1011010 and flipping bit 3 returns a syndrome of 011 that points to position 3

According to Wikipedia, a Hamming code with r parity bits has block length n = 2^r - 1 and message length k = 2^r - r - 1, and the systematic generator matrix G together with the parity-check matrix H encode, detect, and correct any single-bit error

The syndrome and parity-bit calculations are sums taken modulo 2, so the Modulo Calculator is the natural place to verify the same remainder on any dividend and divisor.

Key Concepts Behind the Hamming Code Calculator

Four small ideas explain every result, from the triple-repetition code to the largest Hamming(255,247) block.

Hamming family sizes

For r parity bits the family gives n = 2^r - 1 total bits and k = n - r data bits. The smallest member, Hamming(3,1), is the triple-repetition code. The largest, Hamming(255,247), keeps redundancy under 4%.

Generator matrix G

The k by n matrix that turns a data vector into a codeword. In systematic form the first k positions hold the data bits and the last r positions hold the parity bits.

Parity-check matrix H

The r by n matrix used by the receiver. Multiplying a codeword by H modulo 2 returns the zero vector for an error-free word. A non-zero syndrome names the 1-based position of the flipped bit.

Minimum distance 3

Every Hamming code has minimum distance 3, so it corrects any single-bit error or detects (but not correct) any two-bit error. Layering an overall parity bit forms the SECDED Hamming(8,4) variant used in ECC memory.

The systematic form keeps data bits at the start of the codeword and parity bits at the end, and XOR across carefully chosen bit positions places each parity bit on its own subset.

The matrix multiplication in Hamming codes is built from XOR across carefully chosen bit positions, so the Bitwise Calculator shows the same bitwise operation in a wider AND, OR, XOR, and NOT context when you need the full truth table.

How to Use the Hamming Code Calculator

Five steps move you from a binary string to a corrected data word.

  1. 1 Pick the Hamming family size: Start on the default 7-4 for the textbook example. Switch to 15-11 or 31-26 when the data word is longer.
  2. 2 Choose encode, error-correct, or decode: Use Encode to add parity bits before sending, Error-correct to verify and fix a received codeword, and Decode to strip parity bits back to data.
  3. 3 Enter the binary message: Paste the binary string. Spaces and a leading 0b are stripped, so '1011' and '0b1011' both work.
  4. 4 Match the length to the process: Encode accepts a multiple of k bits; error-correct and decode accept a multiple of n bits. Mismatched lengths surface an invalid-length error.
  5. 5 Read the primary output, syndrome, and verdict: In encode mode the primary output is the codeword. In error-correct mode the syndrome names the flipped bit. In decode mode the primary output is the recovered data.

You are sending 1011 over a noisy channel. Set 7-4, paste 1011, choose encode, and the panel returns 1011010. Switch to error-correct and paste 1001010 (bit 3 flipped in transit); the panel returns the corrected 1011010 with syndrome 011 and error position 3.

When the encoded or decoded message has to be cross-checked in another base, the Binary Converter translates the same 0 and 1 string into decimal, hex, and octal so you can verify the word without retyping.

Benefits of Using the Hamming Code Calculator

Five practical benefits make the same Hamming matrices usable for encoding, error correction, and decoding.

  • Three processes in one tool: Encode, error-correct, and decode share the same input field and the same Hamming matrices, so you can move from sender to receiver without switching calculators.
  • Multiple Hamming family sizes: The size selector covers the triple-repetition code, the textbook Hamming(7,4), and the larger Hamming(15,11), Hamming(31,26), Hamming(127,120), and Hamming(255,247) members.
  • Visible syndrome and error position: The result panel returns the syndrome vector and the 1-based position of any flipped bit, so you can confirm the correction without re-running the matrix multiplication by hand.
  • Tolerant of spaces and a leading 0b: The binary cleaner strips whitespace and a 0b prefix, so pasted dumps and C-style binary literals both work without a preprocessor step.
  • Educational view of a textbook code: The same example data [1,0,1,1] used in Wikipedia and most coding-theory textbooks encodes to 1011010 and shows syndrome 011 when bit 3 is flipped.

The same matrices cover every size in the family, so the calculator doubles as a quick sanity check for textbook homework, and any recovered bit pattern can be turned into a printable character when the data is text.

When the decoded data is actually a text character rather than a raw bit pattern, the ASCII Converter turns the same 0 and 1 string into the matching printable character before downstream processing.

Factors That Affect Hamming Code Calculator Results

Three factors decide which matrix the calculator uses and which inputs it accepts.

Code size

Sets r, n, and k. Larger sizes carry more data bits per codeword but require a longer message. Hamming(255,247) needs 247 data bits to encode a single block.

Process mode

Encode accepts data and returns codewords. Error-correct accepts codewords and returns corrected codewords with a syndrome and error position. Decode accepts codewords and returns data.

Message length

Length must match the chosen mode. Encode requires a multiple of k bits; error-correct and decode require a multiple of n bits. Mismatched lengths surface an invalid-length error.

  • Hamming codes have minimum distance 3, so they correct any single-bit error but cannot correct two-bit errors. If two bits flip, the syndrome still points to a single (wrong) bit. Layer an overall parity bit for SECDED.
  • This calculator works on Hamming codes only, not on BCH or Reed-Solomon. For longer messages or bursty error channels, swap to a stronger code.

Larger sizes carry more data bits per codeword but require a longer input, so pick the smallest size that fits. If the recovered data needs to combine with another binary number, add, subtract, multiply, or divide it with the same register-width workflow.

According to Wikipedia, a Hamming code has minimum distance 3 and therefore corrects any single-bit error while detecting (but not correcting) any two-bit error, which is why real systems layer an overall parity bit on top to form the SECDED Hamming(8,4) variant

If you want to check whether the parity bits of the encoded codeword survive a second operation, the Binary Operations Calculator adds, subtracts, multiplies, or divides the recovered data bits against another binary number in the same register width.

hamming code calculator interface showing the code size selector, process selector, binary message field, and the resulting Hamming codeword with syndrome vector and error position.
hamming code calculator interface showing the code size selector, process selector, binary message field, and the resulting Hamming codeword with syndrome vector and error position.

Frequently Asked Questions

Q: What does the Hamming code calculator do?

A: It encodes a binary data word into a Hamming codeword with r parity bits, detects any single-bit flip using the parity-check matrix and syndrome, and decodes the corrected codeword back to the original data.

Q: How do you encode the data word 1011 with Hamming(7,4)?

A: Data bits 1, 0, 1, 1 fill positions 1 through 4. Three parity bits fill positions 5, 6, and 7 from the binary representation of each data-bit position, giving the codeword 1011010.

Q: How is a single-bit error detected in a Hamming code?

A: The receiver multiplies the received codeword by the transpose of the parity-check matrix H modulo 2. A non-zero syndrome names the 1-based position of the flipped bit; a zero vector means no error.

Q: What is the Hamming(7,4) syndrome for a flipped bit at position 3?

A: The syndrome is 011, which is the binary representation of 3. The receiver flips bit 3 back to recover the original codeword without retransmission.

Q: What is the difference between Hamming code and a parity bit?

A: A single parity bit detects an odd number of bit flips but cannot tell you which bit. A Hamming code uses r parity bits arranged so every single-bit flip produces a unique syndrome that names the flipped bit.

Q: Can a Hamming code correct two flipped bits?

A: No. Every Hamming code has minimum distance 3, which means it corrects any single-bit error and detects (but cannot correct) any two-bit error. Use the SECDED Hamming(8,4) variant for two-bit error detection.