Hamming Distance Calculator

Calculate the Hamming distance between two strings of equal length.

Calculator by SuperCalX: formulas, worked examples and 250+ free calculators.

Your values

Result

Enter your values and the result appears here.

Analysis

Interpretation of the current calculator output

Enter values to see detailed analysis and insights.

How to Use

Step-by-step instructions
  1. 1Enter the first string.
  2. 2Enter the second string (must be same length).
  3. 3The calculator will show the Hamming distance.

Symbol Difference

Counts the number of positions at which the corresponding symbols are different.
Distance = Σ (s1[i] ≠ s2[i])

Variables:

s1First string
s2Second string

Example

Text Comparison

Inputs:

String 1:karolin
String 2:kathrin

Steps:

  1. 1.k=k, a=a, r!=t, o!=h, l!=r, i=i, n=n
  2. 2.Differences: r/t, o/h, l/r
  3. 3.Count = 3
Result:
3

Hamming Distance Calculator: the short answer

The Hamming distance between two strings of equal length is the number of positions where they differ. "karolin" and "kathrin" differ in 3 positions, and the binary strings 1011101 and 1001001 differ in 2. For binary numbers it equals the number of 1s in their XOR.

  • Both strings must be the same length; otherwise use edit (Levenshtein) distance.
  • A code with minimum distance d can detect d − 1 errors and correct ⌊(d − 1)/2⌋.
  • Hamming(7,4) codes have a minimum distance of 3.

By the SuperCalX team · Reviewed by Dr. Ahmed Mortuza Saleque, founder and editor · Last reviewed · How we check our calculators

Uses

  • Error detection and correction; see the Hamming code calculator.
  • DNA and protein sequence comparison.
  • Comparing image hashes to find near-duplicates.
  • Nearest-neighbour search on binary features in machine learning.

Minimum distance of a code

The minimum Hamming distance between any two valid codewords decides how many errors a code can handle. A simple repetition code that sends 000 or 111 has distance 3: it detects up to 2 flipped bits and corrects 1 by majority vote. Hamming(7,4) also has distance 3; adding one more parity bit (SECDED) raises it to 4, so it can correct one error and detect two.

In genetics, the Hamming distance between two DNA sequences of equal length counts point substitutions, a quick measure of how closely they are related.

Worked examples

1011101 vs 1001001

  1. XOR = 0010100.
  2. Count the 1s.

Distance 2.

Common mistakes

  • Comparing strings of different lengths.

Hamming Distance Calculator FAQ

What is the difference between Hamming and Levenshtein distance?

Hamming counts substitutions in equal-length strings; Levenshtein also counts insertions and deletions.

Is the comparison case-sensitive?

Yes; "A" and "a" are different characters with different ASCII codes.

How do I compute Hamming distance for numbers?

XOR them and count the 1 bits. 5 (101) and 3 (011) give 110, a distance of 2.

What is Hamming weight?

The number of non-zero symbols in a string, equal to its Hamming distance from the all-zero string.

Does it work for binary?

Yes, it works for any strings, including binary sequences (e.g., 1011 vs 1001).

Add this calculator to your website

Teachers, bloggers and businesses can show the Hamming Distance Calculator on their own pages for free. Copy this code and paste it into your page's HTML:

Please keep the credit link so readers can find the formula, worked examples and guide.