Skip to content
Everyday

How to Compare Two Texts or Files and Find Differences

Compare two versions of a document, essay, contract or code file and see every change. How diffs work, which view to use, and how to read a unified diff.

Written byAI Online Tools editorial teamUpdated 5 min readPublished

To compare two texts, paste the original into one box and the changed version into the other. A diff checker then highlights every line that was added, removed or changed. Good tools also mark the exact words that differ, let you ignore spacing or capital letters, and export the result as a unified diff. It takes seconds, even for files with thousands of lines.

Tools used in this guide

All free, with no sign-up. They run in your browser.

What a diff is

A diff is a list of the differences between two texts. The name comes from the Unix diff program from the 1970s, and the same idea powers git diff, Google Docs' version history and every code review tool.

Most diff tools work line by line. They look for the longest run of lines the two texts share, in the same order. This is called the longest common subsequence. Every line outside that shared run was either removed from the original or added in the new version.

Our diff checker uses Eugene Myers' diff algorithm, the same approach behind git diff. When a removed line and an added line are similar, it pairs them up and shows them as one changed line. Then it highlights the exact words, or characters, that differ inside that line.

Here's a small example. Compare these two lists:

OriginalChanged
appleapple
bananabanana split
cherrycherry
date

The shared run is "apple … cherry". So the result is one changed line (banana → banana split, with "split" highlighted) and one added line (date).

Side-by-side vs inline view

Diff tools show results in one of two layouts. Both contain the same information.

ViewHow it looksBest for
Side by sideOriginal on the left, changed text on the right, matching lines alignedContracts, essays, anything where you want to read both versions in context
Inline (unified)One column; removed lines marked −, added lines marked +Phones and narrow windows, code reviews, long files with small edits

The diff checker lets you switch layouts with one click and opens in inline view on phones. Use Next change and Previous change (or the N and P keys) to jump between edits without scrolling through unchanged text. Long unchanged stretches are folded away.

Tip: Switch highlighting to Characters when you're hunting for a typo, such as "colour" against "color" or "₹15,000" against "₹1,5000". Leave it on Words for normal reading.

Ignoring whitespace, case and blank lines

Sometimes two texts differ in ways you don't care about. Three options filter those out.

  • Ignore whitespace treats two lines as equal when they differ only in spaces or tabs. Re-indented code, or if(x) against if (x), stops showing up as a change.
  • Ignore case treats "Invoice" and "invoice" as the same.
  • Ignore blank lines skips empty lines, so adding spacing between paragraphs doesn't count as an edit.

The tool also handles line endings quietly. Windows ends each line with two characters (CRLF), while macOS and Linux use one (LF). The checker treats them as the same and tells you if the two texts use different endings. A missing newline at the very end of a file is reported, because it really does change the file.

Warning: Don't use "ignore whitespace" for Python, YAML or Makefiles. In those formats, indentation changes the meaning, so a whitespace-only change can be a real bug.

Moved lines

A line diff only knows two actions: remove and add. So a paragraph you moved from page 1 to page 3 appears as removed in one place and added in another. The diff checker spots identical lines like this and labels both ends moved, so you can tell a reordered clause from a new one.

How to read a unified diff

The unified diff is the standard text format for changes. It's what git diff prints, what you attach to a bug report and what the patch command applies. The diff checker can copy it or download it as a .diff file.

Say a freelance contract changed between two drafts. The unified diff looks like this:

--- a/contract-v1.txt
+++ b/contract-v2.txt
@@ -1,10 +1,11 @@
 1. Term
 The agreement starts on 1 November 2026.
-It runs for 12 months.
+It runs for 24 months.
 
 2. Payment
 The client pays Rs 50,000 per month.
-Invoices are due within 30 days.
+Invoices are due within 15 days.
+Late payments attract 2% interest per month.
 
 3. Notice
 Either party may end the agreement with 30 days' notice.

Read it from the top:

  1. --- and +++ name the two files. a/ is the original and b/ is the changed version.
  2. @@ -1,10 +1,11 @@ is a hunk header. It means this block covers lines 1–10 of the original and lines 1–11 of the new version. The new file is one line longer.
  3. Lines starting with a space are unchanged context. A diff shows up to 3 lines of context around each change so you can see where it sits.
  4. Lines starting with - were removed. Lines starting with + were added.

So in this draft, the term doubled to 24 months, the payment window shrank from 30 to 15 days, and a late-payment clause appeared. Those are exactly the edits you'd want to catch before signing.

If a file has changes far apart, you'll see several @@ headers, one for each block. To apply a downloaded diff, run patch original.txt < changes.diff in a terminal, or git apply inside a repository.

When comparing texts saves you

Contracts and agreements

When the other side sends "the same agreement with minor tweaks", paste both versions and check. Payment terms, notice periods, liability caps and dates are the usual places where small edits hide.

Essays, theses and articles

Compare your draft with your editor's or supervisor's version to see every edit, even if they forgot to turn on tracked changes. It's also useful for checking what changed between a submitted file and the final one.

Code

Paste two versions of a function, or open two files directly. You can drop or open text and code files of up to 20 MB. Turn on "ignore whitespace" when a formatter has re-indented everything and you only want real logic changes.

Configuration files

A server works on staging but not on production? Diff the two .env, nginx.conf or YAML files. A single changed port number or missing line becomes obvious.

Lists and exports

Compare two customer lists, product SKUs or email exports to see what was added or dropped between months. Clean the lists first (see the next section) so formatting noise doesn't hide real differences.

Tips for cleaner comparisons

  • Put one sentence per line for prose. A line diff treats a whole paragraph as one line. Shorter lines give tighter, easier-to-read results.
  • Sort and dedupe lists before comparing. Run both lists through the duplicate line remover with the same sort order, such as A → Z. Then the diff shows true additions and removals, not just reordering.
  • Strip formatting first. Copying from Word or a PDF can bring curly quotes, non-breaking spaces or odd line breaks. If everything shows as changed, paste both texts through a plain-text editor.
  • Check the size of the change. The word counter tells you how many words each version has. A 2,000-word essay that became 2,400 words is worth a closer look, even if the diff looks small.
  • Name your versions. File names appear in the --- and +++ header lines, so contract-v2-client-edits.txt is clearer than final-final.txt when you share the diff.
  • Keep private text private. The diff checker compares both texts in your browser. Nothing is uploaded or saved, so you can paste contracts, salary sheets or source code safely.

Next time someone says "I only changed a couple of things", paste both versions into the diff checker and see for yourself.

Frequently asked questions

Can I compare two Word or PDF files?

A text diff compares plain text. Copy the text out of each Word or PDF file and paste it into the two boxes; formatting such as bold or fonts is not compared, only the words.

Why does the whole paragraph show as changed when I edited one word?

A line diff works line by line, and a paragraph with no line breaks is one long line. The changed words are still highlighted inside it; for long prose, putting one sentence per line gives a clearer result.

Is it safe to compare confidential documents online?

Only if the tool runs in your browser. Our diff checker compares both texts on your device in a background thread and never uploads them, so contracts and code stay on your computer.

How do I compare two lists to find items missing from one?

Sort both lists the same way first, for example with a duplicate line remover set to A to Z, then compare them. Lines only in the original show as removed and lines only in the new list show as added.

All guides