How Text Diff Tools Actually Decide What Changed

A diff tool is not literally finding "your changes" β€” it is calculating the smallest set of edits that turns one text into the other.

Line-level diff is the most common default

Most diff tools compare text line by line first, marking whole lines as added or removed. This is fast and readable, but it can mark an entire line as changed even if you only edited one word in it.

Character or word-level diff shows finer detail

A more granular diff highlights the exact characters or words that changed within a line β€” more precise but visually busier, useful when a small edit is buried in a long line.

Color coding follows a near-universal convention

Most diff tools use green (or similar) for additions and red for deletions, a convention borrowed from version control tools like Git, which makes diffs from different tools easy to read at a glance.

The algorithm looks for the smallest set of changes

Diff algorithms are built on finding the longest common subsequence between two texts, then marking everything outside that shared sequence as changed. The goal is the smallest edit script, not necessarily what feels intuitive to a human.

Moved text often shows as a delete plus an add

If a paragraph is moved to a different location without other changes, most diff tools show it as a deletion in the old spot and an addition in the new spot, since most diff algorithms do not detect relocation as a distinct operation.

Where diffing is used beyond code

Version control is the most familiar use, but diff comparison is just as useful for tracking edits between contract drafts, catching changes in web content over time, or comparing two versions of a document before finalizing it.

Why a tiny edit can produce a large-looking diff

Because line-level diff marks a whole line as changed if even one character differs, a single fixed typo in a long paragraph can visually appear as a full line rewrite. Switching to word or character-level diff view usually clarifies how small the actual change was.

Frequently Asked Questions

Why does the diff show a line as both deleted and added when I only changed one word?

That is how line-level diffing represents an edited line β€” it treats the old line as removed and the new line as added, rather than "partially changed," unless the tool also does inline word-level highlighting within that line.

Can diff tools compare more than just plain text?

Many tools support comparing code, JSON, or other structured formats, though the comparison itself is still fundamentally text-based. Some specialized tools understand a format's structure, like ignoring key order in JSON, rather than just raw text.