Tip: Press Enter in either field to calculate instantly.
What is Levenshtein distance?
Levenshtein distance is a way to measure how different two strings are. It tells you the minimum number of single-character edits needed to transform one string into another. The allowed edits are:
- Insertion (add a character)
- Deletion (remove a character)
- Substitution (replace one character with another)
Example: turning kitten into sitting takes 3 edits, so the Levenshtein distance is 3.
How this calculator works
This Levenshtein distance calculator uses dynamic programming. It builds a matrix where each cell stores the minimum edit cost for prefixes of the two strings. The final answer appears in the bottom-right cell of that matrix.
Distance formula
For each position (i, j), the cost is the minimum of:
- Delete: matrix[i-1][j] + 1
- Insert: matrix[i][j-1] + 1
- Substitute: matrix[i-1][j-1] + cost, where cost is 0 if characters match, otherwise 1
This method guarantees the shortest edit path and runs in O(m × n) time for strings of lengths
m and n.
How to interpret your result
- 0 means the strings are identical.
- A small distance means the strings are very similar.
- A larger distance means they diverge more significantly.
The calculator also reports a normalized similarity percentage, which is useful when comparing strings with different lengths.
Practical use cases
1) Spell checking
A spelling engine can compare a misspelled word to dictionary entries and suggest words with the smallest Levenshtein distance.
2) Fuzzy search
Search systems can return near matches when users mistype a query, improving usability and reducing zero-result searches.
3) Data cleaning and deduplication
Customer records such as “Jon Smith” and “John Smith” can be flagged as possible duplicates using edit distance thresholds.
4) NLP and bioinformatics
In natural language processing and sequence analysis, edit distance helps quantify variation between sequences.
Tips for better string matching
- Normalize case if uppercase/lowercase differences are unimportant.
- Trim extra spaces and punctuation before comparison.
- Use domain-specific thresholds (e.g., 1–2 edits for short names, larger for long product titles).
- Combine Levenshtein distance with phonetic or token-based methods for robust matching.
Levenshtein vs related metrics
- Damerau-Levenshtein distance: adds transposition (swapping adjacent characters) as a single edit.
- Jaro / Jaro-Winkler: often better for short names and typographical errors.
- Hamming distance: only for equal-length strings and counts substitutions only.
Frequently asked questions
Is Levenshtein distance case-sensitive?
By default it is, but this calculator offers an Ignore case option.
Can I compare empty strings?
Yes. If both are empty, the distance is 0. If one is empty and the other has length k, the distance is k.
Does this tool show edit steps?
Yes. For manageable input sizes, it lists one optimal sequence of operations and can also display the dynamic programming matrix.