BINARIOS.ORG

Hamming Distance Calculator

Compare two strings character by character and find how many positions contain different symbols.

Compare two strings

Both strings must have exactly the same number of characters. Spaces and punctuation count as characters.

Example Hamming distances

Binary strings

1011101

1001001

Distance: 2

Text strings

karolin

kathrin

Distance: 3

DNA sequences

GATTACA

GACTATA

Distance: 2

Identical strings

110011

110011

Distance: 0

What is Hamming distance?

The Hamming distance between two equal-length strings is the number of positions where their corresponding symbols differ. It is commonly used in coding theory, digital communications, error detection, bioinformatics, and string comparison.

Formula

For strings \(A\) and \(B\) of length \(n\), the Hamming distance is:

d(A, B) = number of positions i for which Aᵢ ≠ Bᵢ

For example, 1011101 and 1001001 differ at positions 3 and 5, so their Hamming distance is 2.

Hamming distance vs. similarity

This calculator also reports positional similarity, calculated as:

Similarity (%) = 100 × (length − distance) / length

For non-empty strings, a distance of 0 means all positions match. A distance equal to the string length means every position differs. Similarity is a simple positional measure, not a guarantee of semantic similarity.

Important limitations

Frequently asked questions

Can I calculate Hamming distance for binary strings?

Yes. Enter two binary strings of equal length. The distance counts the bit positions that differ.

Why must both strings have equal length?

Hamming distance compares corresponding positions. When strings have different lengths, there is no direct one-to-one positional comparison for every character.

Does a Hamming distance of zero mean the strings are identical?

Yes, after applying the selected case-sensitivity setting. A distance of zero means every compared position matches.

Can I compare DNA sequences?

Yes. Paste two equal-length sequences such as DNA strings. The calculator compares the symbols at each position and counts mismatches.

What is the difference between Hamming and Levenshtein distance?

Hamming distance counts substitutions at corresponding positions and requires equal lengths. Levenshtein distance allows insertions, deletions, and substitutions, so it can compare strings of different lengths.

Related calculators