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.
Levenshtein Distance Calculator
Compare two text values and see the minimum number of edits needed to change one into the other.
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.
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 A | Value B | Distance | Change required |
|---|---|---|---|
Smith | Smyth | 1 | Substitute i with y |
Robrt | Robert | 1 | Insert e |
Smythe | Smyth | 1 | Delete 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:
| Edit | What it does | Example | Distance |
|---|---|---|---|
| Insertion | Adds a missing character | Robrt → Robert | 1 |
| Deletion | Removes an additional character | Smythe → Smyth | 1 |
| Substitution | Replaces one character with another | Smith → Smyth | 1 |
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:
- Substitute
kwiths:kitten→sitten - Substitute
ewithi:sitten→sittin - Insert
g:sittin→sitting
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 A | Value B | Distance | Explanation |
|---|---|---|---|
Smith | Smyth | 1 | Substitute i with y |
Robert | Robrt | 1 | Delete the e |
Smyth | Smythe | 1 | Insert e |
Manchester | Manchster | 1 | Delete the e |
WinPure | WinPuer | 2 | Two substitutions are required |
Data Match | Data Matching | 3 | Add i, n and g |
John Smith | Smith John | 10 | Most 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 A | Value B | Distance | Longer length | Similarity |
|---|---|---|---|---|
Smith | Smyth | 1 | 5 | 80% |
Robert | Robrt | 1 | 6 | 83.3% |
Manchester | Manchster | 1 | 10 | 90% |
Data | Date | 1 | 4 | 75% |
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:
AndersonandAndersen - Company names:
MicrosoftandMicrosft - Locations:
ManchesterandManchster - Product descriptions:
Stainless SteelandStainles Steel - Reference values:
AB12345andAB1235 - Email usernames:
jennifer.smithandjenifer.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 SmithandSmith John - Company-name variations:
The Data Quality CompanyandData Quality Company Ltd - Nicknames:
RobertandBob - Abbreviations:
International Business MachinesandIBM - Phonetically similar names:
StevenandStephen - Synonyms:
CarandAutomobile - Long descriptions: values containing the same information expressed differently
- Transposed characters:
formandfrom
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.
| Operation | Levenshtein | Damerau-Levenshtein |
|---|---|---|
| Insert a character | Yes | Yes |
| Delete a character | Yes | Yes |
| Substitute a character | Yes | Yes |
| Transpose adjacent characters | No | Yes |
Consider the common typing error:
form → from
Standard Levenshtein distance treats this as two substitutions:
- Replace
owithr - Replace
rwitho
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:
Michael→MichealBrian→BrainUnited→Untied12345→12435
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:
| Field | Record A | Record B | Comparison |
|---|---|---|---|
| Name | Jennifer Smith | Jenifer Smith | One missing character |
| Address | 14 London Road | 14 London Road | Exact match |
| Postcode | RG1 4AB | RG1 4AB | Exact match |
j.smith@example.com | j.smith@example.com | Exact 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:
- Compare the values within a selected column.
- Calculate the Levenshtein distance between each candidate pair.
- Convert the distance into a similarity score.
- Compare that score with a chosen matching threshold.
- Combine the result with evidence from other fields and rules.
- 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:
- 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. - 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. - 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. - 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. - 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.
For example, a rule could apply:
| Column | Algorithm | Requirement |
|---|---|---|
| Customer name | Levenshtein | Detect spelling and character-level variations |
| Address | WinPureFuzzy™ | Compare broader address variations |
| Postcode | Exact | Identify identical postcode values |
| Telephone | Exact or normalised comparison | Confirm 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.
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.
Levenshtein distance measures the minimum number of character insertions, deletions and substitutions required to change one text value into another. A lower distance indicates greater character-level similarity.
A distance of 1 means that the values can be made identical with one character change. For example, Smith and Smyth require one substitution, while Robrt and Robert require one insertion.
A lower distance means the strings are more similar. A distance of 0 means they are identical. However, a low distance does not necessarily mean the values represent the same person, organisation or entity.
No. Levenshtein distance is one algorithm that can be used within a fuzzy matching process. Fuzzy matching is a broader approach that may combine multiple algorithms, fields, thresholds and rules to identify similar records.
A common method divides the edit distance by the length of the longer value and subtracts the result from 1. It can then be multiplied by 100 to produce a percentage. However, normalisation methods can vary between software platforms.
There is no single threshold suitable for every dataset. Higher thresholds create stricter matches, while lower thresholds identify more variations but may increase false positives. The appropriate threshold should be tested using representative data and adjusted for each field.
Yes. It is useful for detecting names containing missing, additional or substituted characters, such as Anderson and Andersen. It is less effective for nicknames, phonetic variations and reordered names.
Both algorithms recognise insertions, deletions and substitutions. Damerau-Levenshtein also treats the transposition of two adjacent characters as one edit, making it useful for typing errors such as Michael and Micheal.
Levenshtein distance does not understand pronunciation, word order, abbreviations, synonyms, context or meaning. It should therefore be combined with other algorithms, matching rules and attributes when determining whether complete records represent the same entity.
Share this article



