File Compare

The Complete File Compare Guide

How File Compare tells text files from binary files, how the line diff works, and how SHA-256 hashing verifies binary files match.

Open File Compare

How File Compare Tells Text From Binary

Before comparing anything, the tool needs to decide how to compare it. Each uploaded file is read as raw bytes, and two checks run first, in order: the first several KB are scanned for a null byte - a near-certain sign of binary content - and then the full byte array is run through a strict UTF-8 decode. A file with no null byte that decodes cleanly is treated as text immediately; its extension is never even consulted.

The extension list only comes into play as a fallback: if the strict UTF-8 decode fails but the filename ends in a common text extension (.txt, .md, .json, .csv, .js, .css, .html, .xml, .log, .yml, .yaml, .py, .java, .c, .cpp, .sql, .ini, .conf, and others), the tool gives it one more chance with a lenient decode rather than writing it off - useful for legitimate text files that aren't strictly valid UTF-8. Anything that still fails, along with images, executables, archives, and most office document formats, gets routed to the binary summary view instead of a meaningless line diff.

How the Line Diff Works

Once both files are confirmed as text, they're split into lines and compared using the longest common subsequence (LCS) algorithm - the same underlying technique that powers Git and most source-control diff views. The algorithm finds the largest set of lines that appear in both files, in the same relative order, then marks everything else as either removed (only in File A) or added (only in File B).

The result reads like a standard unified diff: a leading - with a red background for lines only in File A, a leading + with a green background for lines only in File B, and unmarked lines shown for context where both files agree.

SHA-256 Hash Verification for Binary Files

FieldWhat it tells you
SizeA quick sanity check - if sizes differ, the files can't possibly be identical
MIME typeThe browser's best guess at the file's format, from file.type
Last modifiedThe timestamp the operating system recorded for each file
SHA-256 hashA cryptographic fingerprint of the full byte content - the real source of truth

The hash is computed with crypto.subtle.digest('SHA-256', ...), the browser's native, audited Web Crypto implementation. Because SHA-256 is a cryptographic hash, the probability of two genuinely different files sharing the same digest is astronomically small - matching hashes are treated as proof the files are byte-for-byte identical.

Common Use Cases

Verifying DownloadsConfirm a downloaded file matches the original exactly by comparing it against a known-good copy.
Config & Code ReviewSee precisely which lines changed between two versions of a config file, script, or snippet.
Duplicate DetectionQuickly confirm whether two images, PDFs, or archives are truly the same file before deleting one.

Frequently Asked Questions

Why use a cryptographic hash instead of just comparing file sizes or filenames?

Two files can be the exact same size, or even share a filename, while having completely different content. A cryptographic hash like SHA-256 is a fixed-length fingerprint of every byte in the file, so it only matches when the byte content is identical - a far stronger identity check than metadata that can easily be misleading or spoofed.

Could two completely different files ever produce the same SHA-256 hash?

In theory, yes - that's called a hash collision - but no SHA-256 collision has ever been found, and the odds are astronomically smaller than any real-world coincidence. That's why SHA-256, rather than a fast but weak checksum like CRC32, is the standard choice for verifying that a file wasn't corrupted or tampered with.

Why doesn't a line diff show that a block of text was just reordered or reindented, instead of marking it removed and re-added?

A line-based LCS diff only checks whether a line's exact text appears in both files, in the same relative order - it has no concept of a block being "moved" as a unit. A block that changed position shows up as a removal at its old spot and an addition at its new one, and even a one-space reindent turns a line into a completely different string as far as the diff is concerned.

How do file tools in general tell a text file from a binary file?

There's no perfect test, so most tools combine a few heuristics: looking for a null byte (a value that almost never appears in real text), trying to decode the content as a known text encoding like UTF-8, and using the file extension as a hint. None of these is foolproof alone - a corrupted text file can contain a stray null byte, and a renamed binary file can carry a text extension - which is why this tool checks for a null byte and attempts a strict decode before it ever looks at the extension.

Why does a text file sometimes get treated as binary?

Some text-like files use an encoding other than UTF-8, or contain an embedded null byte, which fails the strict-decode check. If the filename's extension is on the tool's text-format list, it gets one more chance with a lenient decode; otherwise - or if a null byte was found - it falls back to the binary summary path so you still get a reliable hash-based comparison.

How large a file can I compare?

There's no hard-coded byte-size limit, but the line diff only runs below roughly 4 million line-pairs (File A's line count times File B's) - beyond that the comparison table would be too expensive to build in a browser tab, so the tool shows a friendly "too large to diff" message instead of freezing. Binary comparison has no such ceiling, since hashing scales with file size, not line count.

Open File Compare