How to Compare Two Texts for Differences (Online, Word, VS Code and Command Line)
· 5 minutes read

Someone sends you "the final version" of a contract, an article comes back from an editor, or a config file suddenly behaves differently. Reading both versions side by side and hunting for changes by eye is slow and you will miss things – a changed number, a removed "not", an extra space.
A diff (short for difference) does the hunting for you: it lines up both texts, tells you which lines were added or removed and, in good tools, highlights the exact words that changed. This guide shows the quickest way to do it online and how to do the same in the programs you probably already use.
The fastest way: compare two texts online
If you just have two pieces of text, the quickest option is our free Text compare tool:
- Paste the original text into the left box.
- Paste the changed text into the right box.
- The differences appear instantly: removed lines are red, added lines green, and the words that changed inside a line get a darker highlight.
- Optionally turn on Ignore whitespace or Ignore case, switch between side by side and unified view, and use Copy diff to save the result.
Everything runs in your browser – the texts are never uploaded, so it is safe for contracts or internal documents. Long unchanged parts are collapsed, so even long files stay readable.
How to compare two documents in Word
Microsoft Word has a built-in compare feature that works on two saved files:
- Open Word and go to Review → Compare → Compare…
- Choose the Original document and the Revised document.
- Click OK. Word opens a new document where all differences are shown as tracked changes, with both originals in side panes.
This keeps formatting changes too, which is useful for contracts. The downside: both versions must be saved .docx files.
How to compare documents in Google Docs
Open the newer document and choose Tools → Compare documents, pick the other document from your Drive and click Compare. Google Docs creates a third document where the differences are shown as suggestions you can accept or reject.
How to compare two files in VS Code or Notepad++
Code editors are great for comparing plain text files, CSV exports or code.
VS Code: select both files in the Explorer (Ctrl/Cmd+click), right-click and choose Compare Selected. From a terminal you can also run:
code --diff old.txt new.txt
Notepad++: install the Compare plugin via Plugins → Plugins Admin, open both files and choose Plugins → Compare → Compare (Ctrl+Alt+C). The files are shown next to each other with changed lines marked.
How to compare two text files on the command line
On Linux and macOS, diff is always available:
diff -u old.txt new.txt
-u prints the unified format with - for removed and + for added lines. Useful flags:
diff -y old.txt new.txt– side by sidediff -w old.txt new.txt– ignore all whitespacediff -i old.txt new.txt– ignore case
If you have Git installed, you can get word-level highlighting even for files outside a repository:
git diff --no-index --word-diff old.txt new.txt
On Windows, the classic command is fc old.txt new.txt. In PowerShell you can compare line sets with:
Compare-Object (Get-Content old.txt) (Get-Content new.txt)
Note that Compare-Object compares lines as sets, so it does not show where in the file a change happened – it is closer to a list comparison than a real diff.
Comparing lists instead of texts
If the order does not matter – for example two lists of e-mails or product codes – a line diff is not the right tool. Moving one item to the top would show up as "removed here, added there". In that case use a list comparison, such as our list compare tool, which tells you which items are only in the first list, only in the second, or in both.
Common pitfalls
- Invisible whitespace. Trailing spaces, tabs versus spaces and non-breaking spaces make lines look identical while the diff says they differ. Turn on Ignore whitespace or clean the text with the spaces remover first.
- Different line endings. Files saved on Windows use
\r\n, on macOS and Linux\n. Our tool treats them the same;diffon the command line does not, so usediff --strip-trailing-crif every line shows up as changed. - Re-wrapped paragraphs. If someone re-flowed a paragraph, every line changes even though only one word did. Comparing paragraphs as single lines (one paragraph per line) gives a much cleaner result.
- Copying from PDFs. Text copied from a PDF often has broken lines and hyphenation. Expect more differences than there really are.
FAQ
What is the best free way to compare two texts?
For quick checks, an online text diff is the fastest – paste both versions and you are done. For documents with formatting, use Word's or Google Docs' compare feature. For files and code, use VS Code or git diff.
Can I compare two texts without uploading them?
Yes. Our Text compare tool runs entirely in your browser with JavaScript, so nothing leaves your computer. Desktop tools like Word, VS Code and diff work offline as well.
How does a diff decide what changed?
Most diff tools, including git diff and ours, use the Myers algorithm. It finds the longest common subsequence of lines – the largest set of lines that appear in both texts in the same order – and reports everything else as added or removed.
Can I ignore changes in capital letters?
Yes. Turn on Ignore case in the online tool, or use diff -i on the command line.