Levenshtein Distance Calculator

Measure how many single-character edits separate two texts.

Levenshtein Distance Calculator

Count every insertion, deletion and substitution needed to turn one text into another.
See the similarity percentage, and follow the edit alignment step by step.
Need to treat a swapped pair as one move? switch to Damerau-Levenshtein in Settings. Results update as you type with Live mode on.


Load an example

Characters: 0; Unique: 0
Characters: 0; Unique: 0
Distance settings
Counts insertions, deletions and substitutions. "kitten" vs "sitting" = 3.
Also counts a swap of two adjacent letters as one move. "teh" vs "the" = 1.

Keeps A and a different. Untick to ignore letter case.
Removes spaces, tabs and line breaks before measuring.
Keeps letters and digits only, dropping spaces and symbols.
Prints the matched, substituted and moved characters.
Enter two texts and press Calculate.


What is Levenshtein Distance?

Imagine you are changing one word into another one letter at a time: any letter can be inserted, deleted, or swapped for another. The Levenshtein distance (also called the edit distance) is the smallest number of those single-character moves that turns the first string into the second. It was introduced in 1965 by the Russian scientist Vladimir Levenshtein as a way to quantify how alike two sequences are, and it is now the backbone of everything from spell-checkers to DNA comparison.

For a concrete feel: to morph kitten into sitting you substitute k→s, e→i, and insert a g; three edits, so the distance is 3. To turn book into back you substitute the two os into a and c, so the distance is 2. The smaller the number, the more alike the texts are.

Three algorithms can compute the distance, each with a different trade-off. The recursive definition follows the math directly but is exponential and only used for teaching. The iterative full-matrix method builds a grid of size m × n, and that is the one our calculator uses because it also reveals the exact alignment of edits. The iterative two-row method keeps only the previous row in memory to save space, at the cost of losing the alignment. Wikipedia's "Levenshtein distance" article has pseudocode for all three.

Research shows the Levenshtein distance cannot be solved in strongly subquadratic time, so comparing very long strings gets expensive fast, because the cost grows with the product of the two lengths. That is why it shines for spotting a short dictionary word inside a long text (spell checkers, OCR correction, fuzzy search) rather than scanning whole novels.


Overview

Our Levenshtein Distance Calculator measures exactly how far apart two texts are by counting the fewest single-character edits (insertions, deletions and substitutions) needed to transform one into the other. It also derives a similarity percentage from that distance, and draws an alignment that lines the two texts up character by character so you can see which letters matched, which were swapped, and where characters were inserted or deleted.

You can switch to Damerau-Levenshtein to count an adjacent-character swap (like the typed as teh) as a single move instead of two substitutions. Case, whitespace and punctuation can be ignored independently, so a messy draft and a clean rewrite still compare fairly. The comparison runs entirely in your browser. Nothing you paste is sent to, or stored on, any server.


Levenshtein Distance Algorithms

Recursive (naive) follows the textbook recurrence straight off the definition: if the last characters match, recurse on the prefixes; otherwise take one plus the cheapest of a deletion, an insertion, or a substitution. Elegant, but it recomputes the same sub-problems and costs exponential time, so it is useful only for tiny strings or as a teaching example.

Iterative with full matrix fills a table row by row, where cell (i, j) holds the distance between the first i source characters and the first j target characters. It runs in O(m × n) time and O(m × n) space, and because it keeps the whole table it supports a back-trace that produces the human-readable alignment, which is the method this calculator uses.

Iterative with two rows keeps only the previous row in memory (O(min(m, n)) space) to save RAM, at the cost of losing the ability to back-trace the alignment. Handy for batch comparisons of long strings where only the raw distance matters.


Levenshtein Distance Applications

Spell checking and autocorrect: candidate words are ranked by their distance to what the user typed, so teh is recognized as a one-move typo of the.

Fuzzy search and deduplication: product names, addresses or usernames that look different but mean the same thing (e.g. Acme Inc. vs Acme Incorporated) are caught by matching on a distance threshold rather than an exact string.

Computational biology: DNA and protein sequences are compared by treating mutations as insertions, deletions and substitutions, with the distance indicating evolutionary closeness.

Version control and patch review: the same min-cost idea powers diff tools that highlight what a change really did, character by character.

Data cleaning and record linkage: when two customer databases use slightly different spellings, the distance helps merge duplicates without a shared ID.


How to Use This Tool

1. Enter your texts: Type or paste your original text into the Source Text box and the text to compare into the Target Text box. Hit Load an example for a ready-made pair, which also computes the result for you.

2. Set the options: Pick Levenshtein for plain edits, or Damerau-Levenshtein to count adjacent-letter swaps as one move. Tick Ignore whitespace or Ignore punctuation to compare only the meaningful characters, and untick Case-sensitive so A and a match. A live pair of counters reports the character and unique-symbol counts under each box.

3. Calculate: With Live mode on (the default), the result appears and updates as you type; press Calculate Distance at any time to refresh it. The result box reports the distance, the similarity percentage, and an alignment that shows each match, substitution, insertion and deletion in its own colour.

4. Save the result: Use Copy to put the whole report on your clipboard, or Download to save it as a .txt file. Press Clear to empty both boxes and start over.


Features and Settings

Two live inputs: Source and Target text areas sit side by side, each with a live counter showing characters and unique symbols, so you always know the scale of what you are comparing.

Metric radio buttons: Levenshtein counts insertions, deletions and substitutions, the classic measure. Damerau-Levenshtein adds adjacent transpositions, so the typo teh vs the drops from a distance of 2 to just 1.

Case-sensitive: Unticked by default, so upper and lower case are treated as the same letter. With color vs Colour the comparison is case-blind, the way most spell-checkers work; ticking it keeps the case mismatch and raises the distance.

Ignore whitespace: Strips spaces, tabs and line breaks before measuring, so a one-space gap does not count as an edit. Useful when re-wrapped text should compare as identical.

Ignore punctuation: Keeps letters and digits only, dropping every symbol. New York, NY and NewYork NY then collapse to the same comparison base.

Show alignment: Prints the full character-by-character trace as coloured blocks: green for matches, orange for substitutions, blue for insertions, red for deletions, and purple for transpositions. Long inputs simply omit the trace to stay fast.

Live mode: On by default. The distance, similarity and alignment refresh automatically every time you type in either box or change a setting, so you can watch the number respond as you edit. Turn it off to freeze the result until you press Calculate Distance.

Distance & similarity report: The headline number is the distance; the similarity percentage is (maxLen - distance) / maxLen × 100 (borrowed from the standard normalized formula), and the difference percentage is its complement. For color vs colour, that is a distance of 1, 83.3% similar, 16.7% different.

Below are two concrete before/after readings produced by the calculator:

Source: color
Target: colour
Levenshtein distance: 1
Similarity: 83.3%  (1 insertion, 0 deletions, 0 substitutions)

Source: teh
Target: the
Levenshtein distance: 2   |   Damerau distance: 1
Similarity: 33.3%  (2 substitutions)   vs   66.7%  (1 transposition)

FAQs

FAQ 1: What does the number actually represent?
Answer: The distance is the minimum count of single-character insertions, deletions and substitutions needed to turn the Source text into the Target text. A distance of 0 means the two texts are identical; the higher the number, the more they differ.

FAQ 2: How is the similarity percentage calculated?
Answer: It uses the standard normalized formula similarity = (max(len(source), len(target)) - distance) / max(len(source), len(target)) × 100. So if the longest text has 6 characters and the distance is 3, the similarity is 50%. An identical pair scores 100%, while a completely different pair of equal length trends toward 0%.

FAQ 3: When would I use Damerau-Levenshtein instead?
Answer: Damerau-Levenshtein treats the swap of two adjacent characters as a single operation. Use it when most of your differences are transposition typos such as teh vs the, or adn vs and, because plain Levenshtein charges two substitutions for each of those swaps.

FAQ 4: Does it handle Unicode, accents and emoji?
Answer: Yes. Texts are compared by Unicode code points via Array.from, so accented letters, CJK characters and emoji each count as a single character even when they are made of several bytes.

FAQ 5: Will it work on very long texts?
Answer: The full-matrix algorithm runs in time and memory proportional to the product of the two lengths. For strings of a few thousand characters it is instant; for tens of thousands it can take a few seconds, and the alignment is automatically omitted to keep the page responsive. For spell-check-style work, keep one side short.

FAQ 6: Is my text stored or sent anywhere?
Answer: No. Every computation happens locally in your browser's JavaScript. Nothing you paste or upload is transmitted to, or saved on, any server; your data stays on your device, even if you refresh or close the tab.


Tools Worth Trying

TextToolz

The Ultimate Text Tools

TextToolz works seamlessly to let you convert and design your text. It is fast, reliable and secure. Trusted by thousands of users.