Hamming distance calculator

Enter two strings of the same length, two binary codes, or two numbers. The calculator counts the positions where they differ, lists those positions and gives the share of positions that match. For numbers it compares their bits with XOR.

Hamming distance3
Similarity
57.14 %
Length (positions)
7
Matching positions
4
Positions that differ (from 1, left to right)
3 4 5

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Choose what to compare: text, binary strings, integers or hex values.
  2. Enter the two values. Text and binary strings must have the same length; spaces inside binary strings are ignored.
  3. Read the distance, the similarity (matching positions ÷ length) and the list of differing positions.

How it works

For strings, the characters at each position are compared and the mismatches are counted. For numbers, the two values are XORed and the 1 bits of the result are counted, which is the same as comparing their binary forms bit by bit.

Similarity = (length − distance) ÷ length.

Worked example

karolin and kathrin, 7 characters each:

Position 1 2 3 4 5 6 7
karolin k a r o l i n
kathrin k a t h r i n

Positions 3 4 5 differ, so the distance is 3, 4 positions match and the similarity is 57.14 %.

For binary codes, 1011101 and 1001001 differ at positions 3 and 5: distance 2.

Tips

  • Same length first. If the lengths differ, the calculator says so instead of guessing how to align them.
  • Error-correcting codes: the smallest distance between any two codewords tells you how many bit errors the code can detect and correct.
  • Image hashes: two 64-bit perceptual hashes with a small distance usually belong to near-identical pictures; paste them in hex mode.

Frequently asked questions

What is the Hamming distance?

It is the number of positions at which two sequences of the same length differ. karolin and kathrin differ in the 3rd, 4th and 5th letters, so their Hamming distance is 3. It counts substitutions only, never insertions or deletions.

What if the strings have different lengths?

The Hamming distance is not defined then. Pad the shorter one if that makes sense for your data, or use the Levenshtein edit distance, which allows insertions and deletions; the text similarity tool on this site computes it.

How is the distance between two numbers computed?

The numbers are compared bit by bit: the distance is the number of 1 bits in a XOR b. 5 is 101 and 3 is 011, their XOR is 110, so the distance is 2. The shorter number is padded with zeros on the left.

Where is the Hamming distance used?

In error-detecting and error-correcting codes (a code with minimum distance d detects d − 1 bit errors and corrects ⌊(d − 1)/2⌋), in comparing perceptual image hashes, in genetics for equal-length DNA sequences, and in nearest-neighbour search over binary vectors.

Are upper and lower case different?

Yes, A and a count as different characters. Characters are whole Unicode characters, so an emoji or an accented letter counts as one position.

More in Developer

All tools in this category: Developer ·Updated November 7, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.