The Unix diff utility was first released in 1974. It was designed for comparing source code files, and the algorithm it pioneered is still running inside Git, GitHub, Google Docs, and every modern text comparison tool. Understanding how it works — and when each comparison mode is useful — helps you choose the right settings for each task.

How Diff Algorithms Work

The core task of any diff tool is finding what changed between two texts. The most common approach is to find the longest common subsequence (LCS) — the largest set of elements that appear in both texts in the same relative order. Everything in the first text but not in the LCS is a deletion. Everything in the second text but not in the LCS is an addition.

For example, comparing "the cat sat on the mat" to "the dog sat on the mat": the LCS is "the — sat on the mat" (seven words). The only non-LCS element is "cat" (deleted) and "dog" (added). The diff correctly identifies that exactly one word changed.

The Myers difference algorithm (1986) is the most widely used implementation because it finds minimal diffs efficiently. Git uses it by default. Modern tools often add a second pass to handle moved blocks and heuristics for cleaner output on real-world text.

Line Diff vs Word Diff

The choice of comparison unit changes what the diff output looks like and what it's useful for.

Line diff compares entire lines as single units. If any character in a line changes, the whole line is marked as deleted and a new line is marked as added. This is the default mode for code and config files, where indentation, line endings, and exact character positions matter. It's fast and produces clean output for structured text.

The limitation: a one-word change in a 30-word sentence shows the entire line as changed. You see something changed; you don't see what.

Word diff compares individual words within lines. It runs the LCS algorithm at the word level rather than the line level. This shows exactly which words were added or removed inside each changed line — far more useful for prose editing, document review, and anywhere the structure of sentences matters more than the structure of lines.

The modern approach used by good diff tools is a two-pass algorithm: line diff first (to identify which lines changed), then word diff within those changed lines (to highlight the specific words). This gives you structural context and precise highlighting in one view.

Compare two texts with word-level highlightingLive diff with side-by-side and unified views. Ignore whitespace and case options. Runs entirely in your browser.
Try it free →

Common Use Cases

Document Review Without Track Changes

When you receive a revised document from a collaborator who didn't use Track Changes, a diff tool lets you see exactly what they changed. Paste the original version on the left, the revised version on the right, and every addition and deletion is immediately visible. This is particularly common with contracts, academic papers, and shared documents edited across different software.

Comparing Configuration Files

Server configuration, CI/CD pipelines, and infrastructure-as-code files are text documents where a single character difference can change behaviour significantly. Line diff is the right mode here — line endings, indentation, and exact character positions matter. Comparing your staging and production configs before a deployment catches drift that accumulated between deployments.

Draft Comparison

Writers often save multiple versions of a piece and later want to reconstruct what changed between drafts, or compare two alternative versions of a section. Word diff in this context is more useful than line diff — you want to see which sentences changed and exactly which words were swapped, not just that a paragraph changed.

Plagiarism and Originality Checking

Comparing a student submission to a suspected source, or checking whether a contractor's work is original versus copied from another client's deliverable, is a common text comparison use case. High similarity percentage combined with minor word substitutions (synonyms swapped throughout) is a common pattern in lightly disguised copying.


Frequently Asked Questions

How does a text diff algorithm work?
Most text diff tools use the Myers difference algorithm, which finds the longest common subsequence (LCS) between two texts. The LCS is the largest set of elements that appear in both texts in the same order. Everything not in the LCS is either an addition (in the new text) or a deletion (from the old text). Myers diff is the same algorithm that Git uses under the hood for version control.
What is the difference between line diff and word diff?
Line diff compares whole lines as units — useful for code, config files, and any text where line breaks carry semantic meaning. A single changed word marks the entire line as changed. Word diff compares individual words, which is more granular and useful for prose editing where you want to see exactly which words changed inside a sentence. Most modern tools run a two-pass approach: line diff for structure, then word diff within changed lines.
Can I use a text diff tool for confidential documents?
If the tool runs entirely in your browser, yes — nothing is uploaded. The comparison happens locally using JavaScript. You can verify this by opening your browser's developer tools, going to the Network tab, and watching for HTTP requests while you type. A browser-based tool sends none. Tools that upload to a server for comparison are not suitable for confidential content.
What is a similarity percentage in a text diff?
Similarity percentage measures how much of the two texts overlap. 100% means they are identical. 0% means they share no characters in sequence. The calculation is typically based on the length of the longest common subsequence divided by the length of the longer text. A 90% similarity usually means a few sentences changed. Below 50% means substantial rewrites. It is a useful quick gauge before examining the detailed diff.
When should I use a text diff tool vs Track Changes in Word?
Track Changes in Word records edits as they are made in a collaborative document. A text diff tool compares any two text versions after the fact — useful when you receive a revised document without Track Changes, when comparing two independently edited versions, when reviewing changes in plain text files, or when you want a visual diff outside of Word's interface. For any text that isn't inside Word, a browser-based diff tool is often faster.