Levenshtein Distance Calculator
Input & Options
Auto-calculate toggle
Quick examples
Custom costs
Damerau-Levenshtein mode for adjacent transpositions
Hamming and LCS comparison modes
DP matrix for short strings
Tips: Ctrl/Cmd + K focuses “A”. Ctrl/Cmd + Enter runs Compare.
Results
A with changes highlighted
B with changes highlighted
Transformation steps
Copy result + CSV batch export
Levenshtein distance guide
Release Updates
v1.1 (June 7, 2026)
- Added Damerau-Levenshtein, Hamming distance, and LCS comparison modes alongside standard Levenshtein distance.
- Added custom operation costs, quick examples, and an optional DP matrix for short strings.
- Added transformation steps, copy result, and CSV batch export for practical string comparison workflows.
What is Levenshtein distance?
Levenshtein distance is the minimum number of single edits needed to turn one string into another. The allowed edits are insertions, deletions, and substitutions. A distance of 0 means the strings are identical; a larger number means more edits are required.
How the edit distance algorithm works
The standard algorithm uses dynamic programming. It builds a grid where rows represent prefixes of String A and columns represent prefixes of String B. Each cell stores the lowest edit cost needed to transform one prefix into the other. The final bottom-right cell is the edit distance, and the highlighted path explains the transformation steps.
- The first row and column represent the cost of inserting or deleting characters from an empty string.
- Each next cell compares delete, insert, and substitute choices.
- The lowest-cost choice becomes the value for that cell.
- Backtracking through the grid produces the visible operation list.
How similarity percentage is calculated
Similarity is shown as 1 - (distance / max(length(A), length(B))). For example, kitten to sitting has a Levenshtein distance of 3. The longer string has 7 characters, so the similarity is about 57.1%. In word mode, length means token count instead of character count.
Character mode vs. word mode
Character mode compares every character, which is best for typos, names, IDs, product codes, DNA-style strings, and short search terms. Word mode compares whitespace-separated tokens, which is better for sentences and short paragraphs where you care about changed words rather than changed letters.
Levenshtein vs Damerau-Levenshtein vs Hamming vs LCS
| Mode | Best for | What it counts |
|---|---|---|
| Levenshtein | General typo and fuzzy-match checks | Insertions, deletions, and substitutions |
| Damerau-Levenshtein | Common keyboard mistakes such as teh vs the |
Levenshtein edits plus adjacent transpositions |
| Hamming | Same-length codes, hashes, fixed fields, and sequence checks | Positions where the two strings differ |
| LCS | Finding shared ordered content between two strings | Longest common subsequence and unmatched tokens |
When to use this calculator
- Fuzzy search: rank results that are close to a user's query even when the query has a typo.
- Data cleanup: spot near-duplicate names, addresses, titles, SKU values, and customer records.
- Form validation: tolerate minor spelling differences while comparing submitted values.
- Content review: compare two short versions of a phrase, sentence, label, or paragraph.
- Learning and debugging: inspect the DP matrix and transformation path behind the score.
Examples: kitten/sitting, book/back, teh/the
| Input A | Input B | Useful mode | What to notice |
|---|---|---|---|
kitten |
sitting |
Levenshtein | Classic example with substitutions plus an insertion. |
book |
back |
Levenshtein | Shows substitutions in the middle of short words. |
teh |
the |
Damerau-Levenshtein | Adjacent transposition mode treats the swapped letters as one edit. |
Limitations: long documents, semantic meaning, transpositions
- Long documents: dynamic programming uses a matrix, so very long inputs can become slower and harder to interpret visually.
- Semantic meaning: edit distance measures surface text changes. It does not know that
carandautomobileare related. - Transpositions: standard Levenshtein does not count swapped adjacent characters as one edit. Use Damerau-Levenshtein for that case.
- Hamming distance: it is most meaningful for equal-length strings. This tool includes length gaps as edits so unequal strings still produce a result.
Frequently asked questions
Do my texts get uploaded?
No. This tool runs entirely in your browser. Your text never leaves your device.
What is Levenshtein distance?
It's the minimum number of single edits (insertions, deletions, substitutions) required to change one string into another.
What’s the difference between character and word mode?
Character mode compares at the character level (good for short strings). Word mode compares tokens split by whitespace (good for sentences/paragraphs).
How is similarity calculated?
Similarity is shown as 1 - (distance / max(length(A), length(B))). In word mode, length means token count.
