Tool to calculate the Hamming distance between two strings of the same length, compare binary or textual words and measure their similarity in seconds.
Hamming Distance - dCode
Tag(s) : Informatics, Data Processing
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
The Hamming distance between two words of the same length, $ n $, is the number of positions at which the corresponding symbols differ. It measures the dissimilarity between two words.
Formally, for two words $ x = (x_1, \dots, x_n) $ and $ y = (y_1, \dots, y_n) $, the Hamming distance is: $$ \operatorname{Hamming}(x,y) = \sum_{i=1}^{n} \mathbf{1}_{x_i \neq y_i} $$
To calculate the Hamming distance between two binary numbers of the same length: compare the bits position by position and count the number of positions where the bits differ.
Example: 10011 and 10101 differ in positions 3 and 4, so the Hamming distance is equal to 2
The generalized Hamming distance can be applied to any string of characters. It counts the number of positions where symbols differ.
Example: DECODE and ENCODE have a Hamming distance of 2 characters.
The Hamming distance measures how different two words of the same length are. It is used to:
— compare two strings or sequences of symbols
— quantify the error between expected and observed data
— measure the similarity between two discrete objects
The smaller the distance, the more similar the two words are. If the distance is zero, the two words are identical.
The distance is undefined if the words do not have the same length
Several codes are based on the Hamming distance, such as the Hamming (7,4) code: 4 data bits, 3 parity bits, or the extended Hamming (8,4) code: 4 data bits, 4 parity bits.
dCode retains ownership of the "Hamming Distance" source code. Any algorithm for the "Hamming Distance" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Hamming Distance" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Hamming Distance" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Hamming Distance" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Hamming Distance on dCode.fr [online website], retrieved on 2026-03-24,