Hamming Distance Calculator

Count differing bits between two equal binary strings.

Technology and NetUpdated 2026-10-161 min read
Hamming Distance Calculator
0/1 only, same length as second.
0/1 only, same length as first.
Hamming distance
...
Similarity...
String length...

What it does

Hamming distance measures how many bits flip between two equal strings. Error codes use it to tell how many flips they can spot or fix. Larger distance means easier separation.

The tool above takes two binary strings and returns distance, similarity, and length. The defaults 1010 and 1001 match the worked example, so the page opens showing distance 2. Type new strings to update all three results.

Counting is positional: compare first with first, second with second, and tally mismatches. Here positions three and four differ, so distance is 2 over length 4 for 50.0 percent same.

Use this for code theory, barcodes, and DNA k-mers in binary form. For hex bytes with XOR totals use a checksum tool instead.

This page shows the method, one full hand checked example at 1010 vs 1001, a reference table, and practice checks that run through the tool.

How to use

  1. Type first string with 0 and 1 only.
  2. Type second string with equal length.
  3. Keep each 1 to 64 bits.
  4. Read Distance as mismatch count.
  5. Read Similarity as same percent.
  6. Pad shorter codes before comparing.

Formula

Distance = count of i with a[i] != b[i]. Similarity = 100 x (length minus distance)/length.
distance
Differing positions.
length
Shared string length.
similarity
Same share in percent.

Equal length required. Spaces and dashes strip first. Non binary stops with a message.

Worked example

Example: 1010 vs 1001

Compare 4 bit strings 1010 and 1001.

  1. Align: 1-1, 0-0, 1-0, 0-1.
  2. First two match, last two differ.
  3. Distance 2.
  4. Same: 4 minus 2 = 2.
  5. Similarity: 100 x 2/4 = 50.0 %.
  6. Length 4 bits.

Reference table

Distances for samples
PairDistanceSimilarity
1010 vs 1001250.0 %
1111 vs 000040.0 %
1010 vs 10100100.0 %

Limits

  • Equal length binary only, 1 to 64 bits.
  • Counts substitutions, not inserts or deletes.
  • No code correction here, only distance.
  • Text needs binary encode first.

Common mistakes

  • Comparing different lengths without padding.
  • Counting matches instead of mismatches.
  • Pasting spaces that change length. This tool strips them first.
  • Using hex without binary convert.
  • Reading similarity as distance.

Try it yourself

Quick checks. Answers sit tucked under each question.

1111 vs 0000?

Distance 4, similarity 0.0 %, length 4 bits.

1010 vs 1010?

Distance 0, similarity 100.0 %, length 4 bits.

Questions

1010 vs 1001?

Distance 2.

Similarity?

Same over length times 100.

Different lengths?

Error here. Pad first.

Max length?

64 bits each here.

Use?

Error detection spacing.

Hex?

Convert to binary first.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.