Diff Checker

Lines added—
Lines removed—
Lines unchanged—
Total diff lines—

How Diff Checker is calculated: Longest common subsequence (LCS) of the two texts: lines in the LCS are unchanged, the rest are added (+) or removed (−); the diff uses the fewest added and removed lines.

What is a diff checker?

A diff checker compares two texts line by line and shows what changed between them. Lines that stayed the same are marked with two spaces. Lines that were removed from the first text are marked with a minus sign. Lines that were added in the second text are marked with a plus sign. The result is a readable list of every difference, in order, with nothing hidden.

The default on this page compares two short lists of fruit. The first text is apple, banana, cherry, date. The second is apple, blueberry, cherry, date, fig. The diff shows 3 unchanged lines, 1 removed line, and 2 added lines: banana was removed, blueberry and fig were added, and apple, cherry, and date stayed the same.

Diffs are how developers, writers, and editors see change. A code review is a diff. A revised document is a diff. A config file before and after an edit is a diff. The format is the same everywhere, because it answers the same question everywhere: what is different, and where.

Everything runs in your browser. The texts you paste never leave your device, and there is no account to create. Paste two texts and the diff appears instantly, with the counts above it.

How a line diff works

The diff is built from the longest common subsequence, which is the longest list of lines that appears in both texts in the same order. For the default example, the longest common subsequence is apple, cherry, date: three lines, in the same order in both texts. Everything in the first text that is not in that subsequence was removed. Everything in the second text that is not in it was added.

The algorithm finds that subsequence with a table. It compares every line of the first text with every line of the second, and fills in a grid of numbers: at each cell, the length of the longest common subsequence from that point on. The grid is filled from the bottom right to the top left, and the top-left cell holds the length of the whole subsequence, which is 3 for the default example.

Then it walks the grid from the top left, following the choices that keep the subsequence longest. When the two current lines match, it takes the line as unchanged and moves both pointers forward. When they do not match, it takes the direction with the larger number: down means the line was removed, right means the line was added. The walk produces the diff in order, line by line.

The result is the smallest possible diff in a specific sense: it uses the fewest added and removed lines, because it keeps the longest possible list of unchanged lines. Two texts that share nothing give a diff of all removals followed by all additions. Two identical texts give a diff of all unchanged lines, with no additions and no removals at all.

Reading a diff: plus, minus, and spaces

A line starting with two spaces is unchanged. It appears in both texts, in the same place relative to the other unchanged lines. Unchanged lines are the anchors of the diff: they show where the changes sit, and they are what make a diff readable, because they give the changes context.

A line starting with a minus sign was removed. It appears in the first text and not in the second. In the default example, banana is the only removed line: it is in the first list and not in the second. Removed lines are shown in the order they appear in the first text.

A line starting with a plus sign was added. It appears in the second text and not in the first. In the default example, blueberry and fig are the added lines: blueberry appears after apple in the second list, and fig appears at the end. Added lines are shown in the order they appear in the second text.

The counts above the diff summarise it: added, removed, unchanged, and total lines in the diff. The default example shows 2 added, 1 removed, 3 unchanged, and 6 lines in total. The total is the size of the diff itself, which is the number of lines you have to read to see every change and its context.

A worked example: three comparisons, three diffs

First, the default: apple, banana, cherry, date against apple, blueberry, cherry, date, fig. The diff is 6 lines: apple unchanged, banana removed, blueberry added, cherry unchanged, date unchanged, fig added. The counts are 2 added, 1 removed, 3 unchanged, 6 in total. Banana was swapped for blueberry, and fig was added at the end.

Second, identical texts: one, two, three against one, two, three. The diff is 3 lines, all unchanged, with 0 added, 0 removed, and 3 unchanged. Nothing changed, and the diff says so by showing no plus or minus lines at all. An empty diff is a valid result, and it is the result you want when you are checking that two files are the same.

Third, completely different texts: alpha, beta against gamma, delta, epsilon. The diff is 5 lines: alpha removed, beta removed, gamma added, delta added, epsilon added. The counts are 3 added, 2 removed, 0 unchanged, 5 in total. When two texts share no lines at all, the diff is the whole first text removed followed by the whole second text added, which is the honest answer.

Try a small edit of your own: change one word in the middle of a paragraph and diff the two versions. The diff shows one removed line and one added line, with the unchanged lines around them giving the context. That is the most common diff in real life: one line changed, everything else the same.

Who uses a diff checker, and why

Developers use diffs every day. A code review is a diff between the old code and the new code. A merge conflict is two diffs that disagree. A config change is a diff between the running config and the new one. The diff checker on this page is the simplest version of that tool, for two texts pasted by hand.

Writers and editors use diffs to see what changed in a revision. A client sends back a document, and the diff shows exactly which paragraphs moved, which sentences were cut, and which lines were added. Reading the diff is faster than reading the whole document twice, and it catches changes that a full read would miss.

Support staff use diffs to compare logs, settings, and error messages. Two log files from two servers, two config files from two machines, two error messages from two versions: the diff shows the one line that differs, and that line is usually the cause of the problem.

Students use diffs to check their work. A word counter counts the words, a line counter counts the lines, and this checker shows what changed between two drafts. Together they cover the basic questions about a text: how big is it, and what is different.

Diff checker vs text diff checker

This page and the text diff checker on this site do different jobs, and it is worth knowing which one you need. This checker is line-based: it compares two texts line by line and shows every added, removed, and unchanged line, in order. It is built for seeing exactly what changed.

The text diff checker is similarity-based: it compares two texts and returns a similarity score, telling you how much they overlap overall. It is built for answering whether two texts are mostly the same, not for showing each change. Use it when the question is how similar, and use this page when the question is what changed.

The difference shows up in the output. This page gives you a line-by-line diff you can read. The similarity checker gives you a number. A number cannot show you which line changed, and a diff cannot tell you at a glance whether two long documents are 90 percent the same. They answer different questions, and both are useful.

In practice, the two are used together. Check similarity first to see whether two documents are close, then run the line diff to see exactly where they differ. A text formatter cleans up a text before diffing it, and remove duplicate lines takes out repeats that would otherwise show up as noise in the diff.

Common diff mistakes

The first mistake is diffing texts with different line breaks. A paragraph pasted as one long line and the same paragraph pasted with hard line breaks will show as completely different, because the diff compares lines, not words. Make sure both texts use the same line breaks before diffing, or the diff will be noise.

The second mistake is trailing spaces. A line with a trailing space is a different line from the same words without one, so the diff shows it as removed and added, even though nothing visible changed. Strip trailing spaces from both texts before diffing, or the diff will be full of false changes.

The third mistake is diffing texts that are too long. This checker diffs the first 500 lines of each text, and says so when it does. A diff of 10,000 lines is unreadable anyway, and the interesting changes are usually near the top. Split long texts into sections and diff one section at a time.

The fourth mistake is reading a diff as a verdict. A diff shows what changed, not whether the change is good. A one-line diff can break a system, and a thousand-line diff can be a harmless reformat. The diff is the starting point for review, not the review itself.

How to use this diff checker

Paste the first text into the first box and the second text into the second box. The diff appears instantly in the output box below, with the counts above it: added, removed, unchanged, and total lines. There is no button to press.

Read the diff line by line. Lines starting with two spaces are unchanged. Lines starting with a minus were removed from the first text. Lines starting with a plus were added in the second text. The unchanged lines give the context, so you can see where each change sits.

Copy the diff with the Copy button next to the output box, or select it and copy it by hand. The counts tell you the size of the change at a glance: a diff with 2 added and 1 removed is a small edit, and a diff with 300 added and 200 removed is a rewrite.

Everything runs in your browser. No sign-up, no account, no data sent anywhere. The texts you pasted never leave your device, and the page works offline once it has loaded. Texts longer than 500 lines are diffed on their first 500 lines only, and the output says so.

Frequently Asked Questions

It was added in the second text. In the default example, blueberry and fig are added lines: they appear in the second list and not in the first. A line starting with minus was removed from the first text, and a line starting with two spaces is unchanged in both.

It is the longest list of lines that appears in both texts in the same order. For apple, banana, cherry, date against apple, blueberry, cherry, date, fig, it is apple, cherry, date. The diff keeps those lines as unchanged and marks everything else as added or removed, which gives the smallest possible diff.

Because the diff compares whole lines, not words. If your text is one long line, changing one word changes the whole line, so the diff shows one removal and one addition. Split the text into shorter lines, one sentence per line, and the diff will show only the sentence that changed.

Yes. This checker diffs the first 500 lines of each text, and the output says so when it truncates. The limit keeps the page fast, because the comparison table grows with the square of the line count. For longer texts, split them into sections and diff one section at a time.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.