Data Matching

Levenshtein Distance: How It Works, Examples & Free Calculator

Levenshtein Distance: How It Works, Examples & Free Calculator

Key Takeaways

  • Levenshtein distance measures the character edits between two values.
  • It works well for spelling mistakes and minor data-entry errors.
  • The distance can be converted into a percentage similarity score.
  • It works best alongside other fields, thresholds and matching algorithms.
  • WinPure AdaptiveMatch™ enables no-code Levenshtein matching at individual-column level.
FREE MATCHING TOOL

Levenshtein Distance Calculator

Compare two text values and see the minimum number of edits needed to change one into the other.

Try an example
3 Levenshtein distance
Moderate similarity

These values differ by 3 edits.

Levenshtein distance counts the minimum number of insertions, deletions and substitutions required to transform one value into the other.

Similarity 57.1%
Longest value 7 chars
Difference 3 edits required
Remember: A low edit distance can indicate similar text, but whether two records are truly the same entity depends on context, field type, thresholds and other matching rules.
From edit distance to intelligent matching

WinPure AdaptiveMatch™ can combine Levenshtein with other algorithms, thresholds and field-level logic to improve matching accuracy across real-world datasets.

What Is Levenshtein Distance?

Definition

Levenshtein Distance

Levenshtein distance is a string-comparison algorithm that measures the minimum number of single-character changes required to transform one value into another. These changes can be an insertion, deletion or substitution.

Value AValue BDistanceChange required
SmithSmyth1Substitute i with y
RobrtRobert1Insert e
SmytheSmyth1Delete e

A distance of 0 means the two values are identical. A distance of 1 means one character change is needed, while a higher distance indicates greater variation between the strings.

In data matching, Levenshtein distance helps identify records that exact matching would overlook because of spelling mistakes, missing characters or data-entry errors. However, it measures textual similarity rather than confirming that two records belong to the same person or organisation. For reliable matching, it should usually be combined with other fields, algorithms and match rules.

How Does the Levenshtein Distance Algorithm Work?

The Levenshtein distance algorithm compares two strings and calculates the smallest number of character edits needed to make them identical. It considers three types of edit:

EditWhat it doesExampleDistance
InsertionAdds a missing characterRobrtRobert1
DeletionRemoves an additional characterSmytheSmyth1
SubstitutionReplaces one character with anotherSmithSmyth1

The algorithm evaluates the characters in both values and finds the transformation requiring the fewest edits. For example, changing kitten into sitting requires three edits:

  1. Substitute k with s: kittensitten
  2. Substitute e with i: sittensittin
  3. Insert g: sittinsitting

The resulting Levenshtein distance is therefore 3.

Levenshtein Distance Examples

The following examples demonstrate how Levenshtein distance measures different types of character-level variation:

Value AValue BDistanceExplanation
SmithSmyth1Substitute i with y
RobertRobrt1Delete the e
SmythSmythe1Insert e
ManchesterManchster1Delete the e
WinPureWinPuer2Two substitutions are required
Data MatchData Matching3Add i, n and g
John SmithSmith John10Most characters move to different positions

These examples show that Levenshtein distance works particularly well when values contain small spelling mistakes, missing characters or additional characters. This makes it useful for comparing fields such as names, locations and short descriptions.

However, it is less effective when words appear in a different order. Although John Smith and Smith John contain exactly the same words, the algorithm reports a high distance because it compares their character positions rather than understanding that the words have been rearranged. A token-based algorithm would generally be more appropriate for this type of variation.

Levenshtein distance also measures textual similarity rather than meaning. For example, cat and car have a distance of 1, despite representing completely different things. This is why a low edit distance should be treated as one piece of matching evidence rather than automatic confirmation that two records represent the same entity.

How Is Levenshtein Distance Converted into a Similarity Score?

Levenshtein distance provides a raw number of edits, but this number does not account for the length of the values being compared. A distance of 1 is significant for a three-character code but relatively minor for a twenty-character company name.

For this reason, matching software commonly converts the raw distance into a normalised similarity score. One widely used calculation is:

Similarity Score = (1 − Levenshtein Distance ÷ Length of the Longer Value) × 100

For example, comparing Smith with Smyth produces a Levenshtein distance of 1. Both values contain five characters:

(1 − 1 ÷ 5) × 100 = 80%

The resulting similarity score is therefore 80%.

Value AValue BDistanceLonger lengthSimilarity
SmithSmyth1580%
RobertRobrt1683.3%
ManchesterManchster11090%
DataDate1475%

The higher the score, the more similar the two strings are:

  • 100% means the values are identical.
  • A score close to 100% indicates only minor character differences.
  • A lower score indicates that more changes are required.

There is no universally correct similarity threshold. A lower threshold may identify more potential matches but also produce more false positives. A higher threshold provides stricter results but may overlook genuine duplicates.

Normalisation methods can also vary between matching systems, so two tools may produce slightly different similarity scores from the same Levenshtein distance. The score should therefore be interpreted alongside the selected threshold, the type of data being compared and evidence from other fields.

When Should Levenshtein Distance Be Used?

Levenshtein distance is most effective when differences between two values are caused by a small number of character-level errors. It is particularly useful for detecting spelling mistakes, missing characters, additional characters and incorrect character substitutions.

Common applications include:

  • Names: Anderson and Andersen
  • Company names: Microsoft and Microsft
  • Locations: Manchester and Manchster
  • Product descriptions: Stainless Steel and Stainles Steel
  • Reference values: AB12345 and AB1235
  • Email usernames: jennifer.smith and jenifer.smith

Best Practice

It works especially well with short or moderately sized values where the character order is expected to remain broadly consistent. It can help data teams identify variations that exact matching would treat as completely different records.

Levenshtein distance can be valuable for:

  • Deduplicating customer and supplier records
  • Matching records across different databases
  • Preparing data for a CRM or ERP migration
  • Detecting data-entry mistakes
  • Standardising reference data
  • Linking records without a reliable shared identifier

However, the algorithm should be used cautiously with identifiers, account numbers and product codes. Two codes separated by only one character may belong to entirely different records rather than being a typing error.

For reliable entity resolution, Levenshtein similarity should normally be combined with evidence from other fields. A similar name becomes much stronger evidence when the records also share an address, postcode, telephone number or date of birth.

When Is Levenshtein Distance Less Effective?

Levenshtein distance becomes less effective when the differences between values involve more than simple character-level errors. It measures how many edits separate two strings, but it does not understand pronunciation, word order, abbreviations, context or meaning.

It may not be the best algorithm for:

  • Reordered words: John Smith and Smith John
  • Company-name variations: The Data Quality Company and Data Quality Company Ltd
  • Nicknames: Robert and Bob
  • Abbreviations: International Business Machines and IBM
  • Phonetically similar names: Steven and Stephen
  • Synonyms: Car and Automobile
  • Long descriptions: values containing the same information expressed differently
  • Transposed characters: form and from

For example, John Smith and Smith John contain the same words but produce a relatively high Levenshtein distance because the characters appear in different positions. Token Sort is better suited to reordered words because it standardises their order before comparing them.

Standard Levenshtein distance can also overstate the difference caused by transposed characters. Changing form into from requires two substitutions under the classical algorithm, even though the error was probably caused by swapping two adjacent letters. Damerau-Levenshtein handles this as one transposition.

Levenshtein distance also cannot determine whether similar strings represent the same entity. Cat and Car are separated by only one edit but have completely different meanings. Conversely, Robert and Bob could refer to the same person despite having limited character similarity.

This is why Levenshtein distance should be selected according to the type of variation expected in the column. Where the data contains reordered words, phonetic differences or abbreviations, another matching algorithm or a combination of algorithms and fields will usually produce more reliable results.

Levenshtein vs Damerau-Levenshtein

Levenshtein and Damerau-Levenshtein both measure the number of character edits required to transform one string into another. The main difference is that Damerau-Levenshtein also recognises the transposition of two adjacent characters as a single edit.

OperationLevenshteinDamerau-Levenshtein
Insert a characterYesYes
Delete a characterYesYes
Substitute a characterYesYes
Transpose adjacent charactersNoYes

Consider the common typing error:

formfrom

Standard Levenshtein distance treats this as two substitutions:

  • Replace o with r
  • Replace r with o

This produces a distance of 2.

Damerau-Levenshtein recognises that the adjacent characters o and r have simply been reversed, producing a distance of 1.

Which algorithm should you use?

Use Levenshtein distance when the most likely differences are:

  • Missing characters
  • Additional characters
  • Incorrect characters
  • Minor spelling variations

Use Damerau-Levenshtein when the data frequently contains adjacent characters entered in the wrong order, such as:

  • MichaelMicheal
  • BrianBrain
  • UnitedUntied
  • 1234512435

Damerau-Levenshtein is often better suited to manually entered data because adjacent-key transpositions are common typing errors. However, neither algorithm understands word order, pronunciation or meaning. The most appropriate choice depends on the errors expected within the column and the other matching evidence available.

How Is Levenshtein Distance Used in Data Matching?

In data matching, Levenshtein distance is used to compare corresponding values and identify records that may represent the same person, organisation or entity despite small character differences. It is also widely used as a string comparator in data-linkage methodologies, including those developed by the Office for National Statistics.

Consider these two customer records:

FieldRecord ARecord BComparison
NameJennifer SmithJenifer SmithOne missing character
Address14 London Road14 London RoadExact match
PostcodeRG1 4ABRG1 4ABExact match
Emailj.smith@example.comj.smith@example.comExact match

Levenshtein identifies the name as highly similar rather than rejecting the records because they are not identical. Combined with the exact agreement across the address, postcode and email, this provides strong evidence that the records belong to the same customer.

A data matching workflow will typically:

  1. Compare the values within a selected column.
  2. Calculate the Levenshtein distance between each candidate pair.
  3. Convert the distance into a similarity score.
  4. Compare that score with a chosen matching threshold.
  5. Combine the result with evidence from other fields and rules.
  6. Classify the records as matches, possible matches or non-matches.

For example, a match rule might require:

  • Name: Levenshtein similarity of at least 85%
  • Postcode: Exact match
  • Address: Fuzzy similarity of at least 90%

This is more reliable than using the name score alone. Two unrelated people can have very similar or even identical names, while genuine duplicate records can contain larger variations.

Levenshtein distance therefore works best as one component of a broader data matching strategy. By combining it with exact comparisons, other matching algorithms and multiple attributes, organisations can detect more genuine duplicates while reducing false matches.

How AdaptiveMatch™ Uses Levenshtein in WinPure

AdaptiveMatch™ is WinPure’s intelligent data matching framework. It helps users create more effective matching rules by analysing the fields being compared and automatically selecting suitable algorithms, weights and matching options for each one.To configure Levenshtein matching:

This is important because different types of data require different comparison methods. An algorithm that works well for a person’s name may not be appropriate for an address, postcode, telephone number or company name. Instead of applying one algorithm across every field, AdaptiveMatch can use the most appropriate method for each column.

For example, AdaptiveMatch might:

  • Use Levenshtein to detect minor spelling and character-entry errors within names.
  • Apply WinPureFuzzy™ to more complex company-name or address variations.
  • Use a phonetic algorithm where names may sound alike but are spelt differently.
  • Apply exact matching to structured fields such as postcodes or email addresses.
  • Assign different weights according to how strongly each field should influence the overall result.

A typical AdaptiveMatch workflow involves:

  1. Import your data
    Add the tables or files you want to deduplicate or compare. Map the corresponding fields, such as Customer Name to Contact Name, and choose whether to find duplicates within one table or match records across multiple sources.
  2. Automatically analyse each field
    AdaptiveMatch™ uses machine learning to identify the type and characteristics of each mapped field. This analysis happens automatically and does not require users to assess every column manually.
  3. Automatically configure the matching
    Based on its analysis, AdaptiveMatch automatically assigns relevant algorithms, weights and matching options to each field. For example, it may select Levenshtein for names containing character-level variations, WinPureFuzzy™ for addresses and exact matching for postcodes.
  4. Optionally refine the configuration
    Most users can proceed with the automatically generated configuration. Advanced users, including data engineers, can review and manually change algorithms, weights, thresholds and other options to meet specific precision, recall or risk requirements.
  5. Run and review the matches
    WinPure applies the combined matching logic and presents the resulting match groups and field-level evidence. Users can then review how each record was matched before deciding whether records should be linked, merged or consolidated.

how adaptive match works

For example, a rule could apply:

ColumnAlgorithmRequirement
Customer nameLevenshteinDetect spelling and character-level variations
AddressWinPureFuzzy™Compare broader address variations
PostcodeExactIdentify identical postcode values
TelephoneExact or normalised comparisonConfirm a shared contact identifier

AdaptiveMatch therefore gives users an intelligent starting point without requiring them to understand every matching algorithm. At the same time, it retains the detailed control experienced data professionals need to inspect, modify and optimise their matching configurations.

Test Levenshtein matching on your own data

Use WinPure to combine Levenshtein with exact, fuzzy and field-level matching rules - without writing code.

Start a free 30-day trial

Levenshtein Distance Without Coding

Levenshtein distance is traditionally implemented using programming languages such as Python, R, Java or SQL extensions. Although open-source libraries make the algorithm available, using it for real-world data matching involves considerably more than comparing two example strings.

Developers may need to build and maintain processes for:

  • Importing and preparing multiple datasets
  • Mapping corresponding columns
  • Normalising similarity scores
  • Selecting and adjusting thresholds
  • Reducing the number of record comparisons
  • Combining results from multiple fields
  • Grouping related records
  • Reviewing possible matches
  • Exporting results and maintaining an audit trail

WinPure makes Levenshtein matching available through a visual, no-code workflow. Users can map their fields, select Levenshtein for the appropriate columns, configure similarity thresholds and combine the results with other algorithms and match rules.

This means data analysts and business users can apply Levenshtein matching across complete datasets without developing a bespoke matching application. Configurations can also be saved and reused, helping organisations apply consistent matching logic to recurring data quality and migration projects.

The algorithm remains only one part of the decision. WinPure provides the wider workflow needed to combine Levenshtein similarity with exact matches and evidence from other attributes, review the resulting groups and make informed decisions about which records should be linked or consolidated.

Conclusion: When to Use Levenshtein Distance

Levenshtein distance is highly effective for identifying values that differ because of missing, additional or substituted characters. It can uncover spelling mistakes and data-entry errors that exact matching would otherwise miss.

However, a low Levenshtein distance does not automatically mean two records represent the same entity. Reliable data matching requires the score to be considered alongside other fields, appropriate thresholds and additional matching algorithms.

With WinPure, users can apply Levenshtein to the columns where it is most suitable, combine it with other comparison methods and review the resulting matches, all without writing code. This provides greater control while helping organisations identify genuine duplicates and reduce false matches.

Written by

Team WinPure

The WinPure Team shares official updates on our products, features, and company news. From new releases and enhancements to behind-the-scenes developments, this space keeps you informed on how WinPure continues to deliver secure, reliable, and innovative data quality solutions.

Have a Data Quality Problem to Solve?

Talk to our team about your data, your requirements, and how WinPure could support your project.

Talk to Our Team

Get practical data quality guidance in your inbox

Receive our latest articles on data cleansing, matching, deduplication, entity resolution, and golden records.

Keep Reading

Start Your 30-Day Trial!

Secure desktop tool. No credit card required.

  • Full-feature access for 30 days
  • Runs on your own machine, data stays local
  • No credit card required
  • Onboarding support from our data team