Hamming Distance Calculator

Stephanie Ben-Joseph headshot Stephanie Ben-Joseph

What this calculator does

The Hamming distance between two sequences of the same length is the number of positions where the two sequences differ. It is a simple, fast way to measure how many substitutions (and only substitutions) are needed to transform one string into another when insertions and deletions are not allowed.

This calculator compares your two inputs character-by-character from left to right and returns the total mismatch count. Because the comparison is positional, the strings must be the same length for the Hamming distance to be defined.

Definition and formula

Let x and y be two strings (or sequences) of equal length n. Their Hamming distance is:

d(x,y) = โˆ‘ i=1 n ฮด(xi,yi)

where the indicator function ฮด is:

In plain language: scan both strings at the same positions and add 1 every time the characters differ.

How to interpret the result

If you want a scale-free measure, you can also compute the normalized distance (sometimes used in analysis):

normalized = d(x,y) / n (a value between 0 and 1). This calculator reports the raw Hamming distance (an integer).

Worked example (step-by-step)

Compare two binary strings of equal length:

x = 1011101
y = 1001001

Compare each position:

Total mismatches = 2, so d(x,y)=2.

Common use cases

Hamming vs. other โ€œstring distanceโ€ measures

Metric Requires equal length? Allowed operations Typical use
Hamming distance Yes Substitutions only (position-by-position mismatches) Bitstrings, codes, aligned sequences
Levenshtein (edit) distance No Insertions, deletions, substitutions Typos, approximate text matching
Jaccard distance No Set overlap of tokens/characters (not positional) Similarity of sets, shingling

Limitations and assumptions (important)

Quick tips

Enter strings of equal length. Spaces and punctuation count as characters.

Enter strings of equal length.

Embed this calculator

Copy and paste the HTML below to add the Hamming Distance Calculator - Measure String Differences to your website.