Compare corresponding positions
The weight wt counts ones, while XOR produces 1 at a mismatch. Equal length n and a common positional alignment are part of the definition.[1]
Distance lies between 0 and n, equals 0 exactly for identical strings and is symmetric. It is not the difference between the numbers represented:0000 and 1000 differ at only one position although their numerical values differ by 8. Insertions and deletions are outside this fixed-position model and require a measure such as edit distance instead.[1]
From pair distance to an error guarantee
C contains at least two distinct codewords of equal length. The guarantees apply to every error pattern up to the stated number of bit flips.[1]
Fewer than dmin flips cannot turn one valid codeword into another, so a received word outside C reveals an error. To correct t errors, Hamming balls of radius t around different codewords must be disjoint. The triangle inequality gives the condition 2t<dmin. A tie between nearest codewords provides no guaranteed unique correction.[1]
Detection and correction are different decoder tasks. The detection bound applies to testing whether the received word is valid; it does not mean that a correction decoder also flags every larger error pattern. A one-word code has no pairwise minimum distance of the form defined here. For a linear binary code, dmin can also be found as the smallest nonzero codeword weight.[1]
- Align the two bit strings by position and first check that their lengths match. Take XOR at each position: equal bits give 0 and unequal bits give 1. Sum the ones to obtain dH(x,y).
- For a code with at least two distinct codewords, calculate the distances between all distinct pairs. Their minimum is dmin. This distance is not the difference between the bit patterns interpreted as integers.
- Fewer than dmin flipped bits cannot change a transmitted codeword into another codeword. A code-membership check therefore detects every pattern of at most dmin−1 bit errors; it does not yet identify the transmitted word.
- For unique correction of up to t errors, the Hamming balls of radius t around distinct codewords must be disjoint: 2t < dmin. Thus t = floor((dmin−1)/2). Beyond this guarantee, nearest-codeword decoding can produce ties or a wrong assignment.
Bit comparison and minimum distance
Compare eight positions without shifting
- Given
- x=10110010 and y=10011001.
- Find
- Find the Hamming distance.
Align the equal-length strings. Positions 3,5,7 and 8 differ.
Form XOR and count its ones.
Result: Four mismatching positions give dH=4.
Check: Positions 1,2,4 and 6 match. Four matches plus four mismatches recover the length 8.
An original three-word code
- Given
- C={00000,11100,00111}; only these three words are valid.
- Find
- How many errors can be detected and corrected with a guarantee?
Check all three distinct pairs instead of just one.
The minimum is 3. Substitute it into the two guarantee formulas.
Result: A validity check detects all patterns with at most 2 errors; nearest-codeword decoding corrects all patterns with at most 1 error.
Check: The word 10000 is one position from 00000. A two-error reception may already be closer to another codeword, so the correction guarantee remains 1.
Recall the method later with the formula’s flashcards.
10 flashcards · English materials
Already have an account? Sign in for flashcardsAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Five distance and coding exercises
Calculate · Foundation
Calculate dH(110010,100110).
Show hint
Mark differences only at corresponding positions.
Learning goal: Count bit mismatches reliably.
Show solution and calculation
Positions 2 and 4 differ, giving XOR 010100 and dH=2.
Rearrange · Application
What minimum distance is required to correct every pattern of up to 2 bit errors?
Show hint
Use 2t<dmin and integer distances.
Learning goal: Derive a distance requirement from correction capability.
Show solution and calculation
The inequality 2·2<dmin requires dmin≥5.
This specifies the needed distance; it does not construct a code of the desired size and length.
Interpret · Foundation
For C={0000,1111}, the received word is 0011. Is nearest-codeword correction unique?
Show hint
Compare both distances.
Learning goal: Recognise a concrete ambiguity beyond the guarantee.
Show solution and calculation
Both codewords are at distance 2, so there is a tie without extra information.
Minimum distance 4 guarantees correction of only 1 error, not 2.
Error analysis · Application
Someone gives distance 8 between 0000 and 1000. Explain the error.
Show hint
Positional difference and numerical value are different models.
Learning goal: Choose the correct distance concept.
Show solution and calculation
Their represented numbers differ by 8, but only the first bit changed.
Hamming distance is 1 and cannot exceed 4 for four-position strings.
Transfer · Challenge
A code has dmin=5. State detection and correction guarantees, and explain why detecting 4 errors does not mean correcting 4.
Show hint
Detection needs invalidity; correction requires a unique assignment.
Learning goal: Apply the two distinct guarantees to one code.
Show solution and calculation
Validity checking detects up to 4 flips.
Suitable decoding corrects up to 2, since 2·2<5.
With 3 or 4 flips, the received word can be closer to a different codeword.
Check your understanding with the formula’s reference test.
5 test questions · English materials
Already have an account? Sign in for the testAvailable from Essential. A ready-made formula set, no AI credits required. Article exercises are not all included.
Errors outside this model
These statements assume fixed known word boundaries and bit flips. Losing a position shifts alignment and creates a different problem. A large minimum distance alone says nothing about code rate, efficient decoding or a channel’s actual error probability; the latter requires a channel model. The examples deliberately use small, fully checkable codes. Hamming distance is also not the same thing as the particular family called Hamming codes. A CRC checksum also detects errors but uses a different construction.[1]
Sources for this explanation
Quanta · Updated November 21, 2026
Editorial responsibility: Quanta Study editorial team
Review scope
This explanation, 2 worked examples and 5 exercises are available in German and English. Structure, source references and mathematical notation undergo automated checks. Calculations, model assumptions and both language versions receive a separate AI review.
An independent, named human subject review has not yet been documented. Our exercise numbers are worked examples, rather than measurements published by the cited sources.
Editorial responsibility, sources and methodsChange history
- Connected the existing four learning steps in the article; clarified absence of physical units and completed the model correction, excluding an overlapping English MC option.
- Added a DE/EN article with a positional model, distance reasoning, an original code and separate error guarantees.
Cite this reference page
Quanta. Hamming distance between bit strings. Updated November 21, 2026. https://quanta-study.de/en/formula-sheet/hamming-distanz-bitfolgen
When citing a specific scientific statement, also cite the specialist source linked to that statement.