Levenshtein Distance Calculator
Introduction: What this Levenshtein Distance Calculator measures
This Levenshtein Distance Calculator measures how many single-character edits separate two strings. It is a compact way to answer a simple question: if you were allowed to insert, delete, or swap one character at a time, how many moves would it take to turn String A into String B?
- Insertion adds one character to match text that is missing a letter or symbol.
- Deletion removes one character when the first string contains an extra letter, digit, or punctuation mark.
- Substitution replaces one character with another when the two strings differ at the same position.
Enter two strings above and click Compute. The calculator returns a whole-number edit count, so a result of 0 means the strings are identical and larger numbers mean the strings need more editing before they match. That makes the score especially useful for spotting typos, alternate spellings, and close text matches.
Definition and formula for Levenshtein distance
In Levenshtein distance, the score between two strings A and B is the minimum number of insertions, deletions, and substitutions required to transform A into B. The calculator follows the classic dynamic-programming approach, which means it compares every prefix of one string against every prefix of the other and keeps the cheapest edit path it has found so far.
Let i be the length of the prefix of A and j the length of the prefix of B. The value d(i, j) is the Levenshtein distance between the first i characters of A and the first j characters of B. The recurrence is:
Here, cost = 0 if the i-th character of A equals the j-th character of B, and cost = 1 otherwise. The first row and first column of the matrix are initialized to represent distances involving an empty string:
- d(0, j) = j (all insertions)
- d(i, 0) = i (all deletions)
The final answer is d(|A|, |B|), where |·| denotes string length. Because the score is based on the cheapest edit path, the calculator always favors the shortest exact sequence of text edits rather than a rough visual guess.
Worked example: editing "kitten" into "sitting"
A classic Levenshtein example compares the words kitten and sitting. The calculator treats the difference as a sequence of character edits, and one optimal route looks like this:
- Substitute
kwiths:kitten → sitten - Substitute
ewithi:sitten → sittin - Insert
gat the end:sittin → sitting
That path uses three single-character edits, so the Levenshtein distance between kitten and sitting is 3. The important point is not the example itself but the method: the calculator checks every plausible combination of insertions, deletions, and substitutions, then reports the smallest count it can prove.
How to interpret a Levenshtein distance result
The Levenshtein calculator returns a non-negative integer, and the simplest way to read that number is as a measure of editing effort:
- 0: the two strings are exactly the same.
- 1–2: the strings are very close, usually differing by a typo, a missing character, or a single replacement.
- 3–5: the strings are still related, but the differences are large enough that you should inspect whether they are alternate spellings, truncated text, or different entries.
- Higher values: the strings diverge more strongly and are less likely to describe the same item.
Keep in mind that a raw Levenshtein distance is length-sensitive. Three edits may be trivial in a long product name and significant in a short code or username. If you need a closer comparison between strings of different lengths, you can normalize the score outside this calculator, but the value shown here is the plain edit distance only.
Comparison with other string similarity metrics for Levenshtein distance
Levenshtein distance is one of several ways to compare strings, and the best metric depends on the type of mismatch you expect. The table below places this calculator's score next to a few familiar alternatives so you can see when the Levenshtein approach is the most natural fit.
| Metric | Key idea | When it is a good fit |
|---|---|---|
| Levenshtein distance | Counts insertions, deletions, and substitutions; all edits cost 1 in this calculator. | General-purpose fuzzy matching where typos, missing characters, and substitutions all matter. |
| Hamming distance | Counts substitutions only; strings must be the same length. | Error-detecting codes, bit strings, or fixed-length IDs where insertions/deletions are impossible. |
| Damerau–Levenshtein | Like Levenshtein but also treats adjacent transpositions (e.g., ab ↔ ba) as a single edit. |
Correcting common keyboard typos where characters are swapped. |
| Jaro / Jaro–Winkler | Weighted comparison based on matching characters and their relative order. | Short strings such as names, where prefix similarity is particularly important. |
If your task needs one of these variants, this page still gives you a solid baseline score under the classic Levenshtein definition. That makes it easy to compare exact edit counts before deciding whether a different similarity metric is a better match for your workflow.
Assumptions and limitations of this Levenshtein Distance Calculator
To keep the Levenshtein calculator predictable, the implementation uses a few straightforward rules that are worth remembering before you rely on the score:
-
Equal edit costs: Insertions, deletions, and substitutions all cost
1. There is no weighting by character type, keyboard layout, or position in the string. - Exact character matching: Characters are compared exactly as entered. By default there is no case folding, accent/diacritic normalization, or Unicode canonicalization unless explicitly performed on your side before input.
-
No transposition operation: Swapping two adjacent characters (e.g.,
ab→ba) counts as two edits (delete + insert or two substitutions), not one. This differs from Damerau–Levenshtein distance. - Performance on very long strings: The dynamic programming algorithm runs in time and memory roughly proportional to the product of the two string lengths. Extremely long inputs (for example, tens of thousands of characters each) may be slow or impractical in a browser environment.
- Raw distance only: The calculator reports the distance, not a normalized similarity score or probability. If your workflow needs a 0–1 similarity value, you will need to transform the result accordingly.
These constraints are typical for a reference implementation of Levenshtein distance and are well suited to everyday text comparison tasks. They are especially useful when you want a transparent score that tells you how far apart two strings are without adding extra assumptions.
Where Levenshtein distance is useful in text matching
Because the Levenshtein distance is simple, consistent, and easy to explain, it shows up in many places where text needs to be compared without requiring an exact match:
- Spell checking and autocorrect: Suggest words from a dictionary that are closest to a misspelling, such as mapping
recievetoreceive. - Fuzzy search: Match user queries that are slightly mistyped against product titles or article names.
- Record linkage and deduplication: Identify near-duplicate customer names across databases (for example,
Jon SmithvsJohn Smyth). - Data cleaning: Standardize free-text entries that contain minor variations, abbreviations, or missing characters.
- Bioinformatics and sequences: Compare DNA, RNA, or protein sequences, treating each base or amino acid as a character (often with domain-specific extensions).
In each of these settings, a lower Levenshtein distance suggests a closer match. Teams often set their own cutoff for what counts as “close enough,” and the calculator makes it easy to see whether two strings fall below or above that threshold.
How to use this Levenshtein Distance Calculator
- Enter String A as the first word, name, phrase, or identifier you want to compare.
- Enter String B as the second string you want to test against String A.
- Click Compute, then compare the reported edit count with any other candidate strings you are considering before you decide which match is closest.
Practice Round: Levenshtein Distance Calculator
Use this quick drill to practice spotting which text inputs are close matches and which are too different to treat as near duplicates.
Start the game, then use your pointer or arrow keys to catch useful string-comparison ideas and avoid bad assumptions.
