Your IP: Unknown · Your Status: ProtectedUnprotectedUnknown

Skip to main content

Hamming distance

Hamming distance

(also hamming metric)

Hamming distance definition

Hamming distance, sometimes referred to as the hamming metric, is a method employed to determine the dissimilarity between two equal-length strings by tallying the number of positions where their respective symbols do not match. Within the realm of error detection and error correction codes, it calculates the bit flips needed to convert one binary code word into another.

Hamming distance examples

For example, the Hamming distance between the binary strings “10101010“ and “11001100“ is 4, as there are four positions where the bits differ.

Comparing the Hamming distance to other metrics

The Hamming distance is often compared to other string similarity metrics, such as the Levenshtein distance, which measures the minimum number of single-character edits (insertions, deletions, or substitutions) needed to change one string into another.

Pros and cons of the Hamming distance


  • Simple and easy to compute.
  • Useful for detecting single-bit errors in error-detecting codes.


  • Only applicable to strings of equal length.
  • Less flexible than other similarity metrics, such as the Levenshtein distance.

Tips for using the Hamming distance

When using the Hamming distance, ensure that the input strings are of equal length. If not, consider using an alternative similarity metric, such as the Levenshtein distance or the Jaccard similarity.

Ultimate digital security