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.

Mismatch Sprint Mini-Game

Count substitutions by instinct. Tap when the pair differs, hold when it matches, and survive escalating signal noise.

Click to Play

Spot mismatches before they pass the scanner. Fast, accurate calls build a streak.

Best score: 0

Time80s
Score0
Streak0
ModeBinary

Tap/click/Space if characters are different. Press Enter if they match. Every 20 seconds, the symbol alphabet mutates.