Levenshtein Distance Calculator
Enter two strings to see how many single-character edits separate them.
Result
How it is calculated
The strings are split into Unicode characters, so an accented letter counts as one character. A table is filled in where cell (i, j) holds the cheapest way to turn the first i characters of A into the first j characters of B: d(i, j) = min(d(i−1, j) + 1, d(i, j−1) + 1, d(i−1, j−1) + c), with c = 0 when the two characters match and c = 1 when they do not. The corner cell is the distance d. Similarity is (1 − d / max(|A|, |B|)) × 100, shown as a percentage with one decimal. The comparison is case-sensitive and spaces count as characters. Two empty strings give no result, and so do pairs where the product of the two lengths exceeds 1,000,000 characters.
Worked example
Compare saturday (8 letters) with sunday (6 letters). Delete the a and the t from saturday to get surday, then replace r with n to get sunday. That is 2 deletions and 1 substitution, so the distance is 3. The longer string has 8 characters, so similarity = (1 − 3 / 8) × 100 = 62.5 %.
Common mistakes
- Expecting upper and lower case to match. Kitten and kitten are one edit apart because the capital K counts as a different character.
- Leaving a trailing space in a pasted string. A space is a character, so abc followed by a space against abc has a distance of 1.
- Reading similarity as a measure of meaning. It only compares characters in order, so two words that mean the same can score low.
- Treating the distance as the number of differing positions. Insertions and deletions shift everything after them, so the distance can be much smaller than a position-by-position comparison suggests.
- Pasting two long texts and expecting a figure. Once the two lengths multiplied pass one million, the tool gives no result, so compare shorter pieces.
About this calculator
The Levenshtein distance between two strings is the minimum number of single-character edits — insertions, deletions or substitutions — needed to turn one string into the other. It was introduced by the Russian mathematician Vladimir Levenshtein in 1965 and is computed with a dynamic-programming grid that builds up the cheapest edit path cell by cell, comparing every prefix of one string against every prefix of the other.
The metric shows up everywhere text needs to be compared imperfectly: spell checkers use it to suggest the closest real word to a typo, search engines and autocomplete use it for fuzzy matching against misspelled queries, bioinformatics tools use a close variant of it to align DNA and protein sequences, and plagiarism detectors and version-control diff tools use it to measure how similar two documents or lines of code really are.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments