Hamming distance is usually thought of as a form of edit distance where only substitutions are permitted. However, it has a more generalized framing as the number of positions whose corresponding values differ between two multidimensional entities.

Consider two vectors and . Then the Hamming distance between them is

where is the Kroenecker delta function function.

Obviously, this function is not well-defined when . For this reason, the Hamming distance is only considered to be a valid measure for sequences of equal length.

When comparisons must be made between sequences of mismatched length, it is typically preferred to use a measure that can accommodate this mismatch, such as the Levenshtein distance. In practice, however, there may be applications where it is desirable to pad the shorter sequence with a null symbol, such that the missing positions are treated as substitutions.