Levenshtein Distance

Counts how many edits turn one string into another: the edit list, a similarity percentage, and the matrix with explanations.

Examples:
Comparison
Extras

Levenshtein distance is the smallest number of edits that turns one string into another. There are three kinds of edits: insert a character, delete one, or replace one. Between "plan" and "planet" the distance is 2: you insert "e" and "t".

How the similarity percentage is calculated

The distance is divided by the largest value possible for strings of that length, and the result is subtracted from one. For "kitten" and "sitting" that gives 1 − 3/7, about 57%. The formula with the actual numbers appears under the result.

The matrix

Turn on "matrix with explanations" to see the calculation table. Each cell holds the distance between the beginnings of the two strings, and the path to the answer is highlighted. Click a cell, and below the table you'll see which neighboring cells the number came from and which edit was chosen.

Rate this tool

Help us get better

Other tools