Ad Space — Top Banner

Hamming Distance Formula

Calculate the number of differing positions between two binary strings.
Used in error detection and correction coding.

The Formula

d(x, y) = number of positions where xᵢ ≠ yᵢ

The Hamming distance counts how many bit positions differ between two strings of equal length. It measures how many single-bit errors would transform one string into the other.

Variables

SymbolMeaning
d(x, y)Hamming distance between strings x and y
x, yTwo binary strings of equal length
xᵢ, yᵢThe bit at position i in strings x and y

Example 1

Find the Hamming distance between 1011101 and 1001001

Position 1: 1 vs 1 ✓

Position 2: 0 vs 0 ✓

Position 3: 1 vs 0 ✗

Position 4: 1 vs 1 ✓

Position 5: 1 vs 0 ✗

Position 6: 0 vs 0 ✓

Position 7: 1 vs 1 ✓

Hamming distance = 2

Example 2

Find the Hamming distance between "karolin" and "kathrin"

k-k ✓, a-a ✓, r-t ✗, o-h ✗, l-r ✗, i-i ✓, n-n ✓

Hamming distance = 3

When to Use It

Use the Hamming distance when:

  • Designing error-detecting and error-correcting codes
  • Measuring similarity between binary data or DNA sequences
  • Implementing spell checkers or fuzzy matching
  • Evaluating the reliability of communication channels

Ad Space — Bottom Banner

Embed This Calculator

Copy the code below and paste it into your website or blog.
The calculator will work directly on your page.