Levenshtein Distance Calculator
Compute the edit distance between two strings with Levenshtein, Damerau-Levenshtein (adds transpositions), or Hamming. Returns distance, similarity percent, and per-operation backtrace counts. Handles strings up to 5,000 characters.
Edit Distance Examples
| Source and target | Method | Distance |
|---|---|---|
| kitten to sitting | Levenshtein | 3 |
| abcd to acbd | Levenshtein | 2 |
| abcd to acbd | Damerau-Levenshtein | 1 |
| karolin to kathrin | Hamming | 3 |
| flaw to lawn | Levenshtein | 2 |
| abcd to abdc | Damerau-Levenshtein | 1 |
Frequently Asked Questions about the Levenshtein Distance Calculator
What is Levenshtein distance and where does the name come from?
Levenshtein distance is the minimum number of single-character insertions, deletions, or substitutions needed to turn one string into another. It was published in 1965 by Soviet mathematician Vladimir Levenshtein in a paper on binary codes capable of correcting deletions, insertions, and reversals. The name stuck even though the same metric had been discovered a few times before; today it underpins spell checkers, fuzzy search, diff tools, and DNA alignment scoring.
How is Damerau-Levenshtein different from regular Levenshtein?
Damerau-Levenshtein adds transposition of adjacent characters as a one-step edit. This calculator implements optimal string alignment, a restricted variant in which a substring cannot be edited more than once. Full Damerau-Levenshtein can produce a different result for some overlapping edits.
What is Hamming distance and why does it require equal-length strings?
Hamming distance counts the positions where two equal-length strings differ, nothing more. Richard Hamming defined it in 1950 for error-detecting and error-correcting codes, where every codeword has a fixed bit length, so 'equal length' is built into the problem. The calculator returns an error rather than padding shorter input because padding would silently change the answer; if you need to compare strings of different length, switch to Levenshtein or Damerau-Levenshtein.
When would I actually use edit distance?
Edit distance can help rank spelling candidates, compare OCR output, or find similar identifiers. It is only one signal: names, natural language, source code, and biological sequences often need domain-specific costs or algorithms. Do not treat a low distance as proof that two records identify the same person or item.
How fast is this for long strings?
This implementation uses O(m x n) dynamic programming, so work grows with the product of the input lengths. The calculator rejects comparisons above one million cells before allocating the table. For larger workloads, use a thresholded, banded, or linear-memory algorithm.
Related Calculators
More calculators in "Tech"
Luhn Checksum CalculatorHTTP Status Code LookupIP CIDR Overlap CalculatorUTF-8 Byte CounterBits to Bytes ConverterBinary to Decimal Converter
See all 98 calculators in "Tech"