Hamming Distance
The number of positions at which two equal-length symbol or bit sequences differ.
Definition
Hamming distance counts the positions at which two equal-length sequences contain different symbols.
For bit strings, the differing positions become 1 after XOR:
distance = popcount(a XOR b)Modern processors can make this very inexpensive for fixed-width hashes or binary embeddings through population-count instructions.
Uses
The metric appears in perceptual hashing, error-correcting codes and binary-feature comparison. It measures substitution-like differences at fixed positions.
Boundary
Hamming distance is directly defined only for equal-length sequences. It does not model insertion or deletion. Problems where sequence length can change require a metric such as edit distance.
A low Hamming distance also has meaning only relative to the representation being compared. Two perceptual hashes being close does not by itself establish identity of the original objects.