# Text diff: modes, counts and when it gets slow

> How character, word and line comparison work, what Additions, Deletions and Changes count, how Windows and Unix line endings are treated, and the practical size limits including the 5,000-character cap in character mode.

- Tool: [Text Diff Tool](https://toolsg.com/en/text-diff)
- Language: en (available: en, zh, ms, ta)
- Last verified against official sources: 2026-10-20
- Source site: ToolSG — a planning guide, not official or financial advice. Cite the agencies listed under Sources.

## Key figures at a glance

| Fact | Value | Source |
| --- | --- | --- |
| Algorithm | Myers shortest edit script — Finds a minimum set of insertions and deletions; Git uses the same family by default. |  |
| Comparison units | Characters, words or lines — Character mode compares Unicode code points; word mode keeps whitespace as units; line mode splits on line breaks (CRLF, LF and CR alike). |  |
| Changes figure | Additions plus Deletions — A replaced word counts as one deletion and one addition, so 2 changes. |  |
| Case and whitespace | Always significant — There is no ignore-case or ignore-whitespace option. |  |

## How a comparison is made

Paste the original text on the left and the modified text on the right, pick a **Comparison Mode** and a **View Mode**, and press **Compare Texts** (Ctrl or Cmd plus Enter also works). It is not live; press Compare again after editing. **Swap Texts** exchanges the two boxes. Both texts stay in your browser.

The page turns each text into a list of units, then runs the Myers algorithm (E. Myers, "An O(ND) Difference Algorithm and Its Variations", 1986) to find the fewest insertions and deletions that turn one list into the other. Tested against an exact longest-common-subsequence calculation on 3,000 random pairs, it always produced a valid and minimal result.

| Mode | Unit | Notes |
| --- | --- | --- |
| Character-level | One Unicode code point | An emoji such as 🙂 is one unit, but an accent written as `e` plus a combining mark is two. |
| Word-level | Words **and** the whitespace between them | Whitespace runs are units of their own, so extra spaces show as changes. |
| Line-level | One line (split on line breaks) | The best choice for code, configuration and lists. CRLF, LF and CR count as the same break. |

## Examples (computed with the page's code)

| Mode | Original | Modified | Diff |
| --- | --- | --- | --- |
| Character | `kitten` | `sitting` | `-k +s`, `i`, `t`, `t`, `-e +i`, `n`, `+g` (3 additions, 2 deletions) |
| Word | `the quick brown fox` | `the quick red fox` | `-brown +red` (1 addition, 1 deletion) |
| Word | `a b` | `a  b` | the single space is removed and a double space added (1 + 1) |
| Line | `l1`, `l2`, `l3` | `l1`, `L2`, `l3` | `-l2 +L2` |
| Character | `a🙂b` | `a😀b` | `-🙂 +😀` |
| Line | `a` + newline | `a` | an extra empty line is removed |

## What the numbers mean

Additions is the number of units only in the modified text, Deletions the number only in the original, and **Changes is their sum**. It is not the number of edited regions. Changing one word is therefore two changes. In word mode the counts include whitespace units, so "words" in the label is approximate. The unit label under each figure (characters, words or lines) tells you what is being counted.

## Things that can surprise you

- **Line endings are normalised.** CRLF (Windows), LF (Unix) and a lone CR (old Mac) are treated as the same line break before comparing in every mode, so `l1`, CRLF, `l2` against `l1`, LF, `l2` shows no differences. Other invisible differences, such as a trailing space, still count; the [line ending detector](https://toolsg.com/en/line-ending-detector) can identify mixed endings.
- **Case and whitespace matter.** `Hello` and `hello` differ, as do tabs and spaces. There is no ignore option; normalise the text first with the [case converter](https://toolsg.com/en/case-converter) or [text minifier](https://toolsg.com/en/text-minifier).
- **Side-by-side panes do not align.** Each pane lists only equal units and its own changes, with no blank filler, so unchanged lines can sit at different heights.
- **Unified view is not a patch file.** In line mode it shows two line-number columns and `+` / `-` markers, but there are no hunk headers or context limits, so you cannot apply it with `patch`.
- **Word mode ignores meaning.** A moved sentence appears as a deletion in one place and an addition in another.

## Size limits and speed

The algorithm keeps a snapshot of its state for every step, so time and memory grow roughly with the square of the number of differences, not with the length of the texts. The page first skips the identical start and end of the two texts, so similar texts are quick: 3,000 lines with one changed line compared in about 3 milliseconds, and two 40,000-character texts that differ by one character in about 6 milliseconds, both in Node.js. Completely different texts are not: two unrelated random strings of 1,000 characters each (2,000 in total) took about 0.7 seconds, 2,000 each about 3 seconds and 2,500 each (5,000 in total, the limit) about 4 seconds in character mode on the test machine; 5,000 each took 22 seconds before the cap existed. Browser speed varies, but the pattern holds.

**Character mode has a limit.** If the parts that differ, counted over both texts together after the identical start and end are ignored, exceed **5,000 characters**, the page shows a message and does not compare. Switch to word or line mode, which have far fewer units, or compare sections. Word and line modes have no such cap, but very large documents (tens of thousands of words) can still be slow.

> **Tip:** If character mode is slow, switch to line or word mode first, then drill into only the lines that changed.

## Common mistakes

- Reading Changes as the number of edits instead of added plus removed units.
- Expecting trailing spaces or tabs to be ignored when comparing text from different systems; only the line-ending style is normalised.
- Using character mode for long documents. Beyond 5,000 differing characters it stops and asks you to switch.
- Expecting the tool to ignore trailing spaces or letter case.

## Related tools

[Line ending detector](https://toolsg.com/en/line-ending-detector) shows CRLF versus LF. [Remove line breaks](https://toolsg.com/en/remove-line-breaks) and [Text sorter](https://toolsg.com/en/text-sorter) tidy lists before comparing. [Hidden character cleaner](https://toolsg.com/en/hidden-character-cleaner) removes invisible differences. [Word counter](https://toolsg.com/en/word-counter) measures the size of each version.

## Frequently asked questions

**Is my text sent to a server?**

No. All text comparison happens entirely in your web browser using JavaScript. Your text never leaves your device, ensuring complete privacy and security for sensitive documents.

**What's the maximum text length I can compare?**

Word and line modes have no fixed limit, though very large texts (tens of thousands of words) can slow your browser. Character mode compares up to 5,000 differing characters (an identical start and end do not count); above that it asks you to switch to word or line mode, because character-by-character comparison needs far more time and memory.

**Can I compare code files with this tool?**

Absolutely! The line-level comparison mode is specifically designed for comparing source code, configuration files, and structured text. It highlights line-by-line differences clearly.

**Which comparison mode should I use?**

Use character-level for precise, character-by-character comparison; word-level for documents and articles; and line-level for code and configuration files. Start with word-level for general text.

**Can I save or export the comparison results?**

Currently, you can copy either the original or modified text to your clipboard using the copy buttons. For permanent storage, take a screenshot of the comparison or save the copied text.

**Does this tool work offline?**

Once the page is loaded, the comparison functionality works without an internet connection since all processing happens in your browser using JavaScript.

**How accurate is the diff algorithm?**

We use a standard Myers diff algorithm, which is the same algorithm used by popular version control systems like Git. It provides accurate and reliable difference detection.

**Can I use this for comparing non-English text?**

Yes! Our tool supports all Unicode characters, making it perfect for comparing text in any language including Chinese, Arabic, Japanese, Korean, and more.

**What does the color coding mean?**

Green highlighting indicates text that was added in the modified version. Red highlighting shows text that was removed. Unchanged text remains unformatted for easy readability.

**Can I compare more than two texts?**

Currently, the tool compares two texts at a time. To compare multiple versions, perform pairwise comparisons between different versions.


## Sources

- [Git — git-diff documentation (--diff-algorithm)](https://git-scm.com/docs/git-diff) — Describes Myers as the basic greedy algorithm and the current default.
- [MDN — String iterator (code points)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Symbol.iterator)
