Hamming Distance Calculator

Count the positions where two equal-length strings differ and see their positional similarity instantly.

Compare Two Sequences
Enter strings of the same length. Letters, digits, spaces, and symbols are compared exactly.

About the Hamming distance calculator

Hamming distance measures how many corresponding positions differ between two strings of equal length. Compare the strings one character at a time and add one whenever the characters do not match. The final count is the Hamming distance. A distance of zero means the strings are identical, while a distance equal to the string length means every position differs. The concept was named for mathematician Richard Hamming and is fundamental to coding theory and digital communication. For example, the words hello and hallo differ only at their second position, so their Hamming distance is one. The binary strings 1011101 and 1001001 differ at positions three and five, giving a distance of two. This tool reports positions using one-based numbering, which means the first character is position one rather than index zero. It also calculates positional similarity as matching positions divided by total length, expressed as a percentage. Equal lengths are essential to the standard definition. Hamming distance describes substitutions only: one character at a position is replaced by another. It does not account for insertions or deletions because either operation shifts later positions and prevents a direct one-to-one comparison. For strings of different lengths, an edit-distance measure such as Levenshtein distance is usually more appropriate. This calculator therefore rejects unequal inputs instead of silently padding or trimming them. Hamming distance is widely used in error-detecting and error-correcting codes. Valid codewords are designed to be separated by a minimum distance. If a received word differs from a valid word by only a small number of bits, a decoder can infer which transmission errors may have occurred. A code with minimum distance three can detect up to two bit errors and correct one bit error under standard assumptions. The measure also appears in information theory, cryptography, clustering, computer vision, and biological sequence analysis. Hash comparisons may count differing bits to study avalanche behavior, and binary feature vectors can be compared efficiently with exclusive-or operations. This calculator performs an exact character comparison and is case-sensitive, so uppercase A differs from lowercase a. Spaces and punctuation also count as characters. Use consistently formatted inputs and verify that both sequences represent aligned observations before interpreting the result.

Hamming distance examples

SequencesDistanceDiffering positions
hello and hallo1Only position 2 differs.
1011101 and 10010012Positions 3 and 5 differ.
karolin and kathrin3Positions 3, 4, and 5 differ.

How to calculate Hamming distance

  1. Enter the first sequence exactly as it should be compared.
  2. Enter a second sequence containing the same number of characters.
  3. Select Calculate Hamming Distance to count mismatched positions.
  4. Review the distance, similarity percentage, and one-based mismatch positions.

Hamming distance FAQ

What does a Hamming distance of zero mean?

It means every character matches at the corresponding position. The two sequences are therefore identical under an exact, case-sensitive comparison.

Can the strings have different lengths?

No, standard Hamming distance is defined for equal-length strings. Use Levenshtein or another edit distance when insertions and deletions must be considered.

Is the comparison case-sensitive?

Yes, uppercase and lowercase letters are treated as different characters. Normalize the letter case before entering strings if your analysis should ignore capitalization.

How is the similarity percentage calculated?

The calculator subtracts the distance from the sequence length, then divides by that length. Multiplying by 100 converts the matching share into a percentage.

How is Hamming distance used in error correction?

Coding systems separate valid codewords by known minimum distances. A receiver can use the nearest valid codeword to detect or correct a limited number of changed bits.