UTILS.
100% in-browser

Hamming Distance Calculator

Count the positions where two equal-length strings, bitstrings, or hex values differ, with a normalized distance and a highlighted mismatch diff.

output

About this tool

The Hamming Distance Calculator counts the positions at which two equal-length inputs differ — the core metric behind error-detecting and error-correcting codes. Both inputs must be the same length; if they are not, the tool shows a clear error with each length rather than guessing an alignment. It reports the raw distance, the normalized distance (distance ÷ length, from 0 to 1), the comparison length, the number of matching positions, and a per-position diff that highlights every mismatch in red.

Three modes cover the common cases. In text mode it compares the strings code point by code point, so equal length means the same number of characters. In binary mode it validates that each input contains only 0s and 1s of equal length and counts the differing bit positions — equivalently the popcount of their XOR. In hex mode it parses both inputs as hexadecimal of equal digit length, XORs them nibble by nibble, and sums the set bits, giving the true bit-level Hamming distance; the length here is the total number of bits (hex digits × 4).

The computation is pure, deterministic, and fully offline — nothing you enter leaves your browser. Hamming distance is used to measure how many single-bit errors separate two codewords, to compare fixed-length hashes or fingerprints, and in bioinformatics to compare equal-length sequences. Because it requires equal lengths, use edit distance instead when the strings can differ in length.

Frequently asked questions

Why do the two inputs have to be the same length?
Hamming distance is defined only for equal-length sequences — it compares position i of one against position i of the other. If the lengths differ there is no canonical alignment, so the tool reports an error with both lengths. For inputs of different lengths, use Levenshtein (edit) distance instead.
What does binary mode count?
It validates that both inputs are strings of 0s and 1s of equal length, then counts the bit positions that differ — the same as the population count (number of set bits) of the XOR of the two bitstrings.
How does hex mode compute the distance?
Each hex digit is a nibble (4 bits). The tool XORs the two values digit by digit and sums the set bits across all nibbles, giving the bit-level Hamming distance. The length used for normalization is the total bit count, i.e. the number of hex digits times four.
What is the normalized distance?
It is the raw distance divided by the comparison length, a value between 0 (identical) and 1 (every position differs). It lets you compare mismatch rates across inputs of different lengths on the same 0–1 scale.

More tools