Levenshtein Distance Calculator

Compare two strings, count the edit distance between them, and see how similar they are.

This calculator runs entirely in your browser. Nothing you type is uploaded.

How to use this tool

Paste or type one string into each box, then press Calculate distance. The tool returns the Levenshtein distance (the smallest number of single-character edits needed to change one string into the other) and a similarity percentage. Choose case insensitive if you want "Hello" and "hello" treated as the same. Use the Copy result button to copy a plain-text summary, or Clear to start over.

How the Levenshtein distance works

The Levenshtein distance, also called edit distance, counts how many single-character insertions, deletions, or substitutions it takes to transform one string into another. It is solved with a simple dynamic-programming table where each cell holds the cost of matching a prefix of one string against a prefix of the other.

distance = minimum number of insertions, deletions, and substitutions
similarity = 1 - (distance / length of the longer string)
similarity percentage = similarity * 100

For each character pair the table takes the smallest of three options: the cost above plus one (a deletion), the cost to the left plus one (an insertion), or the diagonal cost plus zero or one (a match or a substitution). The bottom-right cell of the table is the final distance. Two identical strings have a distance of zero and a similarity of 100 percent. If both strings are empty, the similarity is treated as 100 percent because there is nothing to differ.

A real example

Compare "kitten" and "sitting". You substitute the k for an s ("sitten"), substitute the e for an i ("sittin"), and insert a g at the end ("sitting"). That is three edits, so the Levenshtein distance is 3. The longer string has 7 characters, so the similarity is 1 - 3/7 = 0.571, or about 57.1 percent.

Common questions

What is a Levenshtein distance calculator used for?

It measures how different two strings are by counting the edits between them. It is common in spell checkers, fuzzy search, deduplication, DNA and text comparison, and anywhere you need to compare two strings and score their similarity.

How is the similarity percentage calculated?

The tool divides the edit distance by the length of the longer string, subtracts that from one, and multiplies by 100. A distance of 0 gives 100 percent similarity, while a distance equal to the longer string's length gives 0 percent.

Does it count spaces and punctuation?

Yes. Every character matters, including spaces, punctuation, and line breaks. If you do not want case to matter, switch the comparison setting to case insensitive.

Is the same as Hamming distance?

No. Hamming distance only compares strings of equal length position by position and only counts substitutions. Levenshtein distance also allows insertions and deletions, so it works for strings of different lengths.

Are my strings sent anywhere?

No. The entire calculation happens in your browser with plain JavaScript. Nothing you paste leaves your device or is stored on a server.