For equal-length sequences, the Hamming distance counts the columns that differ.

highlighted = computed this step

Count the columns that differ

When two sequences have the SAME length, the Hamming distance is just the number of positions where they disagree. Here 2 columns differ.

dH=2d_H = 2
Hamming distanceThe two strands line up column for column; the highlighted columns differ.seq 1GCATGCseq 2GCTAGC

Hamming needs equal lengths

Hamming distance cannot compare sequences of different lengths: it has no way to express an insertion or deletion, only a substitution in a fixed column. A single inserted base would shift every later column and inflate the count. The next lesson fixes this with edit distance.

requires s=t\text{requires } |s| = |t|
Hamming distanceThe two strands line up column for column; the highlighted columns differ.seq 1GCATGCseq 2GCTAGC