Levenshtein Distance Calculator

Calculate the Levenshtein edit distance and similarity between two strings, with the exact edit steps listed.

The second one is the optimal string alignment (OSA) variant.

Edit distance
โ€”
Similarity
โ€”
Length A
0
Length B
0

Type in both boxes to compare them.

No uploads. Your files stay on your device.

Free forever, no sign-up, no cookies. Buy me a coffee

How it works

The Levenshtein distance between two strings is the smallest number of single-character insertions, deletions and substitutions needed to turn one into the other. This page computes the full edit distance defined by Levenshtein (1965) with the classic Wagner-Fischer dynamic-programming matrix, then walks that matrix backwards to recover the actual edit steps, so you can see exactly where the two strings diverge. The textbook example, "kitten" and "sitting", has a distance of 3.

Switching the algorithm to Damerau-Levenshtein uses the optimal string alignment (OSA) variant, which also allows swapping two adjacent characters at a cost of 1, so "ab" and "ba" score 1 instead of 2. OSA is the restricted form: no substring may be edited more than once, so "CA" to "ABC" still costs 3, not 2. Similarity is reported as 1 minus the distance divided by the length of the longer string. Characters are counted as Unicode code points, so accented letters and emoji count as one character each, though a base letter plus a combining mark counts as two. Everything runs in your browser and nothing you type is uploaded.

Frequently asked questions

What is the Levenshtein distance between two strings?

It is the smallest number of single-character insertions, deletions and substitutions needed to turn one string into the other. The textbook example is "kitten" and "sitting", which has a distance of 3: substitute k with s, substitute e with i, and insert g at the end. This calculator computes that number with the Wagner-Fischer dynamic-programming matrix and also lists the individual edit steps it found.

What is the difference between Levenshtein and Damerau-Levenshtein?

Damerau-Levenshtein adds a fourth operation: swapping two adjacent characters counts as one edit instead of two, which matches how typos usually happen. So "ab" and "ba" score 1 with Damerau-Levenshtein and 2 with plain Levenshtein. This page implements the optimal string alignment (OSA) variant, the restricted form in which no substring is edited more than once, so "CA" to "ABC" still costs 3.

How is the similarity percentage calculated?

Similarity is 1 minus the edit distance divided by the length of the longer string, shown as a percentage. For "kitten" and "sitting" that is 1 minus 3 divided by 7, or 57.14%. Two identical strings score 100%, and two strings with nothing in common score 0%. Characters are counted as Unicode code points, so accented letters and emoji each count as one.

Report a bug