Text Diff β Compare Two Texts and See Exactly What Changed
Learn how text diff works, the difference between line, word, and character diff modes, how to read unified diff format, and when to use a text diff tool for documents, code, and configuration files.
By sadiqbd Β· June 6, 2026
Comparing two pieces of text is harder than it looks when the differences are subtle
A document went through revisions and you need to know exactly what changed. Two code snippets look similar but behave differently β where do they actually differ? A configuration file was edited and you're not sure which settings changed. A contract has two versions and you need to identify every deviation between them.
Text diff shows you the exact differences between two texts β additions, deletions, and modifications β highlighted clearly so nothing is missed.
How Text Diff Works
Diff algorithms compare two texts and identify the minimum set of changes that transforms one into the other. The classic algorithm is Eugene Myers' 1986 diff algorithm, which is the basis of the Unix diff command and most modern diff tools.
The output classifies each line or character as:
- Unchanged β appears in both texts as-is
- Deleted β present in the first text but not the second
- Added β present in the second text but not the first
- Modified β a line changed between versions (shown as deletion + addition in line diff; highlighted characters in character diff)
Diff Modes
Line diff (unified diff)
The standard format β compares text line by line. Shows which complete lines were added, removed, or changed. Best for comparing code, configurations, and structured text where lines are meaningful units.
This line is unchanged
- This line was removed
+ This line was added
This is also unchanged
Word diff
Compares at the word level β shows which specific words changed within lines. Useful when lines are long and the change is a word or phrase, not the whole line.
Character diff (inline diff)
Shows the exact characters that changed within a line β highlights even single-character differences. Most useful for spotting small changes in code identifiers, numbers, or precise formatting.
How to Use the Text Diff Tool on sadiqbd.com
- Paste text A β the original or first version
- Paste text B β the modified or second version
- Select diff mode β line, word, or character
- Compare β the tool highlights differences
- Read the result β additions in green, deletions in red, unchanged text in neutral colour
Real-World Examples
Document version comparison
A terms-of-service document went through legal review. You need to identify every sentence that changed for the compliance team:
Text A: the original ToS Text B: the revised ToS
Line diff shows: 3 sections modified, 1 paragraph added, 1 clause removed. The compliance team reviews only the marked sections rather than reading the entire document.
Code review
Two versions of a function β the original and a bug fix. Character diff highlights that a > comparison was changed to >= β a one-character fix that changes boundary condition behaviour.
Without diff, reviewing character by character: error-prone. With diff: the change is immediately visible.
Configuration file audit
A server's nginx configuration before and after deployment. Line diff shows:
- One
server_namedirective changed - A
proxy_passURL updated - A new
locationblock added
Confirming these are the only changes verifies the deployment is clean.
Contract comparison
Two versions of a contract from negotiations. Word diff shows the specific phrases that changed β "may" becoming "shall," "reasonable efforts" becoming "best efforts," a liability cap changing from $50,000 to $25,000. Each change has material legal significance; the diff ensures none are missed.
Checking copy changes
A marketing email was edited by multiple team members. The diff shows what copy was revised from the original draft, making it easy to review the editorial decisions.
Reading Unified Diff Format
The standard unified diff format (used by git diff and most code diff tools) has a specific structure:
--- file_a.txt 2024-06-10
+++ file_b.txt 2024-06-10
@@ -1,5 +1,6 @@
Line 1 (unchanged)
-Line 2 (deleted from original)
+Line 2 modified (added in new version)
+New line 3 (added)
Line 4 (unchanged)
Line 5 (unchanged)
---identifies the original file+++identifies the new file@@shows which line numbers the chunk covers:-1,5means original lines 1β5;+1,6means new file lines 1β6-prefix: deleted (in original, not in new)+prefix: added (in new, not in original)prefix (space): unchanged context
Diff in Version Control
Git's git diff command uses the same algorithms β it's essentially a text diff applied to files tracked by version control. Understanding text diff helps you read git diff output more fluently.
git diff HEAD~1 β shows what changed in the last commit
git diff branch-a branch-b β compares two branches
git diff --word-diff β word-level diff for more readable prose comparison
The text diff tool works for ad-hoc comparisons without needing a Git repository β just paste two texts.
Character-Level vs. Line-Level Diff: When Each Is Better
Line diff is better for:
- Code where changes are usually whole lines (function adds, removes, rewrites)
- Configuration files where each setting is on its own line
- Logs where each event is a single line
- Documents where paragraph-level comparison is sufficient
Character diff is better for:
- Prose where changes might be single words or characters within a paragraph
- Finding typos or subtle character changes
- Comparing strings, data values, or identifiers where one character changed
Tips for Text Diff
Normalise formatting before diffing if you only care about content. If the two texts have different indentation, line endings (CRLF vs. LF), or whitespace patterns, many irrelevant differences appear. Normalising first produces a cleaner, more meaningful diff.
Use word diff for prose comparison. When comparing articles, essays, or marketing copy, word diff shows which specific phrases changed rather than flagging entire paragraphs as different.
Focus on the most significant changes first. For large diffs, start with the added and deleted sections (structural changes), then review modifications (content changes).
Frequently Asked Questions
Can text diff handle very long documents?
Browser-based diff tools can handle documents up to a few hundred kilobytes. For very large files (multi-megabyte logs, large codebases), use command-line diff or a dedicated code review tool.
Does diff detect moved paragraphs? Standard diff doesn't detect moved content β a paragraph moved from one section to another appears as a deletion at the old position and an addition at the new position. Some advanced diff tools have move detection, but standard text diff doesn't.
What if the two texts are completely different? The diff will show the entire first text as deleted and the entire second text as added β which is technically correct but not very useful. Text diff is most valuable when texts share substantial content with targeted changes.
Can I diff non-English text? Yes β text diff works on any Unicode text, including Arabic, Bengali, Chinese, and other scripts.
Is the text diff tool free? Yes β completely free, no sign-up required.
Text diff turns the laborious task of manual comparison into a visual scan. For document review, code comparison, configuration auditing, and contract analysis, it makes the differences undeniable.
Try the Text Diff tool free at sadiqbd.com β compare any two texts and see exactly what changed, added, or removed.