The Hamming distance calculator above answers one narrow question precisely: in how many positions do these two equal-length sequences disagree? It reports the count, lists the positions, and expresses the result as a fraction of the length so distances from sequences of different sizes can be compared sensibly.
Arb Digital builds free tools that state their limits as clearly as their outputs, and this one has a sharp limit worth stating up front. Hamming distance is defined only between sequences of equal length, and it is positional. If a character has been inserted or deleted rather than substituted, every position after the change shifts, the distance shoots up, and the number stops being a useful measure of how similar the two strings really are. That is not a flaw in the metric, it is what the metric means.
What This Hamming Distance Calculator Does
It walks the two inputs in step and increments a counter every time the pair at a given position is unequal. That is the entire algorithm, and its simplicity is the point. The NIST Dictionary of Algorithms and Data Structures gives the definition as the number of bits which differ between two binary strings, and the same idea extends to any alphabet: symbols rather than bits, positions rather than bit indices.
The tool offers four ways to read the inputs, because "distance" means slightly different things depending on what you think a position is. Character mode treats each character as one position, which is the definition you meet in string algorithms and in the standard example. Binary mode expects only zeros and ones and counts flipped bits. Hex mode expands each hex digit to four bits before counting, so a distance of one means one flipped bit rather than one different digit. Text expanded to bits encodes each input as UTF-8 and compares the bytes bit by bit, which is what actually happens on a wire.
Those last two modes matter more than they look. Two hex strings differing in one digit can differ by one, two, three or four bits depending on which digit changed, and if you are reasoning about error rates or code distances then the bit count is the number you need. The tool reports both the byte-level and bit-level view so the gap is visible rather than assumed.
How to Use It
- Choose the comparison mode first. It changes what counts as a position, and therefore changes the answer, so setting it after typing tends to produce a surprise.
- Paste both values. They must be the same length. If they are not, the tool says so and reports the length difference instead of returning a misleading number.
- Decide about letter case. Folding case is right when comparing user-entered identifiers and wrong when comparing raw data, because in the underlying bytes an upper and lower case letter genuinely differ.
- Read the positions list. The count tells you how much disagreement there is; the positions tell you whether it is clustered, which usually means a burst, or scattered, which usually means independent noise.
- Use the relative distance to compare across lengths. Three differences in seven characters and three in seventy are not the same result.
The Formula: How the Distance Is Computed
For two sequences a and b of the same length n, the Hamming distance is the number of indices i from 1 to n where ai ≠ bi. For binary sequences this is the same as the population count of the bitwise exclusive-or, because exclusive-or produces a one exactly where the inputs disagree.
Work the default. Comparing "karolin" with "kathrin" character by character: k matches k, a matches a, r against t differs, o against h differs, l against r differs, i matches i, n matches n. Three positions disagree, so the distance is three out of seven, a relative distance of 0.429 and a similarity of 57.1 per cent. This is the textbook example and it is a good check that any implementation is doing what it claims.
The binary example is equally direct. Comparing 1011101 with 1001001 the third and fifth bits differ and nothing else does, so the distance is two. Exclusive-oring the two words gives 0010100, which has exactly two set bits, confirming the population-count identity.
Why It Is a Metric, and Why That Is Useful
Hamming distance satisfies the three properties that make something a metric in the mathematical sense. It is zero exactly when the sequences are identical, it is symmetric so swapping the inputs changes nothing, and it obeys the triangle inequality: the distance from a to c never exceeds the distance from a to b plus the distance from b to c.
That last property is what makes error-correcting codes possible, and it is the reason the metric is introduced early in communications courses such as MIT OpenCourseWare 6.02, Introduction to EECS II: Digital Communication Systems, whose readings move from bit errors straight into linear block codes. If every pair of valid codewords is at least distance three apart, then any word with a single error is closer to the codeword it came from than to any other, so the nearest valid codeword is provably the right answer. Distance four gives you enough room to notice two errors without being able to pick between candidates, which is the difference between correcting and merely detecting. The Hamming code calculator puts that reasoning to work, building a code with exactly that minimum distance and using it to repair a flipped bit.
The boundary between the two pages in one sentence: this tool measures the distance between two sequences you supply, while the code calculator constructs sequences that are guaranteed to be far enough apart to be repairable. The parity bit calculator sits at the bottom of the same scale, producing a code with minimum distance two, which detects a single error and corrects none.
Where the Metric Quietly Fails
The most common misuse is treating Hamming distance as a general measure of string similarity. It is not one. Compare "abcdef" with "bcdefg" and every character disagrees, giving the maximum possible distance of six, even though the second string is the first shifted by one and shares five characters in order. Any alignment problem, spell-checking, DNA comparison, fuzzy matching on names, needs a metric that allows insertions and deletions, and Hamming does not.
The second failure is subtler. In character mode the tool compares Unicode code units, and a visually identical string can be encoded differently. An accented letter may be one precomposed code point or a base letter followed by a combining mark, which is a different length and a different comparison entirely. Normalising both inputs before comparing is the fix, and it is a step people skip because the two strings look the same on screen.
The third is trusting the count without the positions. Three scattered differences in a hundred-bit word and three adjacent ones suggest completely different causes: the first looks like random noise, the second like a burst from interference or a physical defect. The count alone cannot distinguish them, which is why this tool lists the positions rather than only summarising.
Practical Uses Beyond Coding Theory
Perceptual hashing is the clearest everyday example. Image and audio fingerprints are built so that similar media produce similar fixed-length hashes, and the comparison at the end is a Hamming distance with a threshold. Two photographs are judged to be the same picture if their hashes differ in fewer than some number of bits. The metric is doing real work there precisely because the hashes are all the same length by construction.
Nearest-neighbour search over binary embeddings works the same way, as does locality-sensitive hashing, where the whole design goal is that the Hamming distance between hashes approximates a distance in the original space. In genetics, comparing aligned sequences of equal length is a Hamming distance, though the moment insertions enter the picture the field switches to alignment-based measures instead.
It also appears in ordinary engineering diagnosis. If you have a known-good bit pattern and a captured one, the distance tells you how badly a link is behaving, and the pattern of positions tells you where to look. For a byte-level rather than positional comparison of file contents, the checksum comparator answers the different question of whether two files are identical at all, and the diff checker handles the line-level case where content has moved.
Arb Digital builds free tools like this one because useful pages earn attention. If you want tools, calculators or content built for your own audience, we can help.
Browse All Free Tools Talk to Arb DigitalCommon Mistakes to Avoid
- Comparing strings of different lengths — the metric is undefined there, and padding one to match invents differences that were never in the data.
- Using it for fuzzy text matching — a single inserted character shifts everything after it and the distance stops meaning anything useful.
- Counting hex digits instead of bits — one changed hex digit can be one to four flipped bits, and coding theory cares about the bits.
- Ignoring Unicode normalisation — two strings that look identical can differ in code points, so normalise before comparing.
- Reading the count without the positions — clustered and scattered differences point at completely different underlying causes.
Related Free Tools From Arb Digital
Put the metric to work with the Hamming code calculator, or see the minimal case in the parity bit calculator. Convert inputs first with the text to binary converter, the binary to text converter or the number base converter. The bitwise calculator performs the exclusive-or that underlies the bit count, the diff checker compares text that has shifted rather than merely changed, and the character counter confirms your two inputs really are the same length. The rest of the collection is in the free online tools hub.
Frequently Asked Questions
It is the number of positions at which the two sequences hold different symbols. For the standard example, karolin and kathrin differ at the third, fourth and fifth characters, so their Hamming distance is three.
Because the metric is defined position against position. With unequal lengths there is no correct way to pair the symbols up, and padding the shorter one manufactures differences that were never in the data. The tool reports the mismatch rather than guessing.
This page measures how far apart two sequences you supply already are. The code calculator constructs sequences that are guaranteed to sit far enough apart that a flipped bit can be located and repaired. One is a measurement, the other is an encoding.
No. Those problems involve insertions and deletions, which shift every following position and send the Hamming distance to nearly its maximum even for very similar strings. Alignment-based measures that allow insertions are the right tool there.
Bits, if you are reasoning about errors or code distances. One changed hex digit represents anywhere from one to four flipped bits, so counting digits understates the bit-level distance by an unpredictable amount. The hex mode here expands to bits for that reason.
For binary sequences it is the number of set bits in the exclusive-or of the two words. Exclusive-or produces a one exactly where the inputs disagree, so counting those ones gives the distance directly. That identity is why the operation is so cheap in hardware.
Because folding case makes an upper and lower case letter count as matching. That is often what you want for user-entered text and never what you want for raw data, since in the underlying bytes the two genuinely differ.
It is the distance divided by the length, so it puts results from sequences of different sizes on the same scale. Three differences in seven positions is a relative distance of 0.429, while three in seventy is 0.043, and treating those as equivalent would be misleading.