๐Ÿ”ค Levenshtein Distance Calculator

3Edit distance
57%Similarity
Transformation breakdown
kโ†’sitteโ†’ing
MatchSubstituteInsertDelete

Calculates the minimum number of single-character insertions, deletions, and substitutions needed to turn one string into another (the edit distance, or Levenshtein distance), and visualizes which characters changed with color-coded chips. Useful for spell-checking, string similarity scoring, or learning fuzzy-search algorithms.

How to use

  1. Enter the two strings you want to compare.
  2. The edit distance and similarity percentage are calculated automatically.
  3. The breakdown of the transformation (matches, substitutions, insertions, deletions) is shown as color-coded chips.

How the calculation works

The Levenshtein distance (edit distance), devised by Vladimir Levenshtein in 1965, is the minimum number of single-character insertions, deletions and substitutions needed to turn one string into another. This tool fills a dynamic-programming table with the distance between the first i characters of one string and the first j of the other: d[i][j] = d[iโˆ’1][jโˆ’1] if the characters match, otherwise 1 + min(d[iโˆ’1][jโˆ’1], d[iโˆ’1][j], d[i][jโˆ’1]) The bottom-right cell is the answer. The table is then traced back to show which characters were changed and how. Similarity is 1 โˆ’ distance รท length of the longer string, as a percentage. Characters are counted as code points, so an emoji counts as one.

Worked example

"kitten" โ†’ "sitting" 1. Substitute k with s (sitten) 2. Substitute e with i (sittin) 3. Insert g at the end (sitting) Distance: 3 Similarity: 1 โˆ’ 3 รท 7 โ‰ˆ 57% "ๆฑไบฌ" โ†’ "ไบฌ้ƒฝ": distance 2 (delete ๆฑ, insert ้ƒฝ)

Things to be aware of

  • Used for spelling suggestions ("did you meanโ€ฆ"), finding near-duplicate records and comparing DNA sequences.
  • The work grows with the product of the two lengths, so comparing strings of thousands of characters can be slow.
  • Swapping two adjacent characters (ab โ†’ ba) counts as two edits here. The variant that counts it as one is the Damerauโ€“Levenshtein distance.

FAQ

What is edit distance (Levenshtein distance)?

It's the minimum number of single-character insert, delete, and substitute operations needed to turn one string into another.

How is the similarity percentage calculated?

It's 1 minus (edit distance รท length of the longer string), shown as a percentage. A higher value means the two strings are more similar.

Is the comparison case-sensitive?

Yes, the current version compares strings case-sensitively.