Hamming Distance Calculator

Find the Hamming distance.

Result

3
OK

How it is calculated

The Hamming distance between two strings of the same length is the number of positions at which their characters are different: d = Σ [aᵢ ≠ bᵢ]. The engine walks along both strings from the first character to the last, adds 1 whenever the two characters at the same position are not equal, and shows the total. The comparison is exact: upper and lower case count as different characters, and spaces count like any other character. If the two strings have different lengths the distance is not defined, so the tool shows a dash and a message about unequal length. Both fields must be filled. The comparison works on bytes, so accented or non-Latin characters can take up more than one position. It is used for binary words, DNA and error detection.

Worked example

Compare the words karolin and kathrin, which both have 7 characters. Position by position: k = k, a = a, r and t differ, o and h differ, l and r differ, i = i, n = n. Three positions are different (the 3rd, 4th and 5th), so the Hamming distance is 3. The tool reports 3 with the status OK. If one of the words had 8 characters, there would be no result, because a position-by-position comparison needs equal lengths.

Try this example →

Common mistakes

  • Comparing strings of different length and expecting a number. Hamming distance needs equal lengths; use the Levenshtein edit distance when letters can be inserted or removed.
  • Forgetting that case matters, so "Karolin" and "karolin" already differ in position 1.
  • Leaving a space or newline at the end of one string, which makes the lengths unequal.
  • Expecting the result to be a percentage. It is a plain count of differing positions, so divide by the length yourself for a ratio.

About this calculator

This calculator finds the Hamming distance between two equal-length strings — the number of positions at which the corresponding characters differ. It works on text, binary strings, or DNA sequences, comparing character by character.

Computer science students use it to check homework on error-detecting codes, network engineers use the same concept to measure bit errors in transmitted data, and bioinformatics students use it to compare DNA or protein sequences.

Was this helpful?

You can pick up to 3 reactions.

Comments

  • Be the first to comment.

Popular calculators

All Calculators