Text Diff Explained
A diff checker lines up two texts and marks every line that was removed (red, minus) or added (green, plus), using the smallest possible set of changes. Paste the original on the left and the new version on the right, then pick line diff for code or word diff to see exactly which words changed. Everything runs in your browser.
A diff (short for difference) algorithm compares two texts and identifies what changed between them. The classic algorithm, Longest Common Subsequence (LCS), finds the longest sequence of lines that appear in both texts in the same order: lines not in this sequence are either added or deleted.
The Unix diff command has been the standard for code comparison since 1974. Git, GitHub, and virtually all version control systems use diff under the hood to show what changed between commits.
How Diff Works
Line vs Word Diff
Use Cases
Privacy
Worked Example: the Sample Texts
The two texts loaded on this page differ in three places. Line diff reports 3 lines deleted, 3 added and 2 unchanged: lines 1, 4 and 5 of A were replaced, while "Hello world" and "Line three" match.
| Line | Line diff shows | Word diff marks |
|---|---|---|
| 1 | Whole line removed and added | jumps to leaps, dog to cat |
| 2 and 3 | Unchanged | Unchanged |
| 4 | Whole line removed and added | will be deleted removed; is a brand new, added to B added |
| 5 | Whole line removed and added | A to B |
Word diff pairs the first removed line of a changed block with the first added line, the second with the second, and so on. Extra lines on either side are shown whole.
What Each Kind of Change Looks Like
| Change | Result | Tip |
|---|---|---|
| One word edited | 1 line removed, 1 added | Use word diff to see the word |
| Line inserted | 1 line added, nothing removed | Nothing to fix, it is a plain addition |
| Line moved | Removed in one place, added in another | Diffs do not detect moves |
| Indentation or trailing spaces | Lines look the same but are marked | Turn on Ignore whitespace |
| Tabs vs spaces | Marked as changed | Ignore whitespace treats any run of spaces or tabs as one space |
| Reformatted JSON | Many lines changed | Format both sides the same way first |
How the Comparison Works
The checker first skips the lines both texts share at the start and the end, then runs the Myers diff algorithm on what is left. Myers finds the shortest edit script, the fewest deletions and insertions that turn A into B, in time proportional to the text length times the number of differences, so two long files with a few edits compare almost instantly. Word diff runs the same algorithm again inside each changed line, on words, spaces and punctuation marks.
Line numbers refer to text A for removed and unchanged lines and to text B for added lines. Ignore whitespace compares lines after trimming them and collapsing runs of spaces and tabs, so a b and a b count as equal but ab and a b do not.
Tips for cleaner diffs
- Format structured data before comparing: run both versions through the JSON formatter or the SQL formatter with the same settings.
- Sort lists that have no meaningful order, such as dependency lists, so only real changes remain.
- Compare plain text, not rich text. Copying from Word or a PDF can add invisible characters such as non-breaking spaces.