String Distance Calculator
Compare two strings with Levenshtein, Damerau-Levenshtein, and Hamming distance. Plus a similarity percentage you can use as a fuzzy-match threshold.
Similarity
57.1%
Levenshtein
3
Damerau-Lev.
3
Hamming
n/a
Damerau-Levenshtein treats ab → ba (a transposition) as one edit; plain Levenshtein counts it as two. Hamming only works for strings of equal length.
How to use
- Type or paste two strings.
- Read off each distance metric and the similarity %.
- Use ~85%+ similarity as a starting threshold for fuzzy deduplication, lower for typo-tolerant search.
About this tool
ShowHide
Type two strings and see how far apart they are under several edit-distance metrics at once. Levenshtein counts insertions, deletions and substitutions — the classic spell-check measure, where kitten and sitting are three edits apart. Damerau-Levenshtein additionally treats a swap of two adjacent characters as a single edit, which matches how people actually mistype: ac and ca are two edits under Levenshtein and one under Damerau. Hamming counts position-by-position mismatches and is only defined when the strings are the same length, which makes it the right tool for fixed-width codes and the wrong one for free text. The similarity percentage is (1 − levenshtein / longer length) × 100, which is the number you would threshold on when deduplicating records.
The comparison runs over UTF-16 code units, and that has consequences worth knowing before you trust a distance. An emoji outside the basic plane is two code units, so deleting one counts as two edits rather than one. More awkwardly, two strings that look identical on screen can have a non-zero distance: café written with a precomposed é is four units, and the same word with e followed by a combining acute accent is five, giving a distance of 1 between two things no reader would call different. Normalise both sides — String.prototype.normalize('NFC') — before comparing anything that came from different sources, because text pasted from a Mac, a database and a web form will not agree on this by itself.
Choosing the right metric matters more than tuning the threshold. Edit distance treats every character as equally important, so Smith and Smyth score the same as Smith and Smith., though one is a different name and the other is punctuation. For matching personal names, Jaro-Winkler weights a shared prefix more heavily and does better; for matching sentences, token-based measures beat character-based ones outright. And raw distance is not comparable across lengths — three edits in a five-character string is a different event from three edits in a hundred-character one, which is exactly what the percentage is there to correct for.
Frequently asked questions
Which metric should I use?
For typed text where humans transpose adjacent characters, use Damerau-Levenshtein. For protein sequences or fixed-length codes use Hamming. For everything else (URL slugs, names, free text) Levenshtein is the safe default — and what most spell-check libraries use internally.
How does similarity % relate to the distances?
It's a normalized Levenshtein: 100% means identical, 0% means every character has to be replaced. The denominator is the longer of the two strings, so cat vs dog is 0% (3 edits / 3 chars) but cat vs catt is 75% (1 edit / 4 chars).
Why is Hamming sometimes 'n/a'?
Hamming distance is only defined for equal-length strings. If lengths differ, there's no meaningful pairwise position comparison — use Levenshtein instead.
Is this case-sensitive?
Yes. Cat vs cat has Levenshtein distance 1. Lowercase both inputs first if you want case-insensitive comparison.
Related tools
Reverse Text
Reverse text four ways — by characters, word order, the letters inside each word, or line order. Works with emoji and any language.
Text
Text Repeater
Repeat a word, line or block of text any number of times — joined by a new line, space, comma, nothing, or your own separator.
Text
Markdown Stats & Reading Time
Count words, sentences, headings, links, code blocks, and estimate reading / speaking time for any Markdown.
Text
Reading Time & Speaking Time Calculator
Estimate how long it takes to read or speak a text — adjustable WPM presets for slow, average, fast readers, TED, podcast.
Text
Readability Calculator (Flesch-Kincaid, SMOG)
Score any English text on six classic readability formulas — Flesch Reading Ease, Flesch-Kincaid, Gunning Fog, SMOG, ARI and Coleman-Liau.
Text
Character & Word Counter
Count characters, words, sentences, lines, and bytes in real time.
Text