You need to compare binary files — a compiled executable, a firmware image, a
PDF, a SQLite database — and your usual text diff tool returns garbage or nothing at all.
A binary file
does not have lines, newlines, or readable characters, so standard diff
falls short. This guide walks through every reliable method for binary comparison:
from the fastest one-liner commands on any OS to dedicated GUI hex editors, plus the one
workflow most tutorials skip — using binary diff results to drive meaningful source-code review.
If you work on Linux, you may already be familiar with
the core Linux file comparison commands;
this article goes deeper on the binary-specific path.
What Is Binary Compare and When Do You Need It?
A binary comparison inspects two files byte by byte rather than line by line. Where a text diff looks for changed rows of human-readable characters, a binary diff reports the exact byte offset and old/new values for every point where the files diverge. The output is more granular — and often far harder to interpret — but it is the only approach that works reliably on non-text data.
Common use cases
- Firmware and embedded images. Verifying that a firmware build matches the expected artifact, or pinpointing exactly which bytes changed between firmware versions before flashing a device.
- Build artifact integrity. Confirming that two independently compiled binaries from the same source are bit-for-bit identical (reproducible builds). Any unexpected difference signals a toolchain issue, a timestamp embedding, or a non-deterministic code path.
- Malware and security analysis. Comparing a suspicious executable to a known clean version to locate injected or patched bytes — a common step in reverse engineering and incident response.
- File recovery and data forensics. Checking whether a recovered file matches the original, or identifying which sectors of a disk image differ from a reference backup.
- Version control of compiled assets. Detecting unintentional changes to compiled outputs, PDFs, Office documents, or SQLite databases that are tracked in a repository but are not human-readable.
- Protocol and network capture analysis. Diffing binary packet captures (PCAP files) to find unexpected payload differences between two sessions.
In all of these scenarios, the goal is the same: identify where the files differ and, if possible, understand why. The "where" is answered by binary diff tools; the "why" usually requires going back to source code — which is where text-based diff tools re-enter the picture.
Binary Diff vs Text Diff: Key Differences
The most common People Also Ask question on this topic is: "What's the difference between binary diff and text diff?" The answer comes down to three things: unit of comparison, output format, and what the tool can and cannot interpret.
0x7D (file1) differs from 0x7E (file2). The red highlight shows the single diverging byte.Unit of comparison
A text diff splits files into lines and compares those lines as strings.
It relies on newline characters (0x0A or 0x0D 0x0A) to define
boundaries. If a file has no newlines — or if byte values happen to form sequences that
a text tool misinterprets as multi-byte characters — the output is unreliable or empty.
A binary diff (or binary file comparison) has no concept of lines. It reads both files as streams of raw bytes and compares them position by position. The output reports byte offsets (in decimal or hexadecimal) and the differing byte values.
Output format
Text diff output looks like this (unified diff):
-old line content
+new line content
Binary diff output looks like this (cmp -l style):
1234 125 126 That means: at byte offset 1234 (decimal), file 1 has octal value 125 and file 2 has octal value 126. Not immediately readable, but precise.
What tools can interpret
Text diff tools understand context — they can show you surrounding lines, collapse
identical regions, and highlight word-level changes within a line. Binary diff tools
understand position — they can tell you offset 0x1A3F changed from 0x00
to 0xFF, but they have no concept of what that offset means structurally inside
the file format. Understanding the structure (a PE header, an ELF section, a ZIP local
file header) requires additional knowledge of the file format.
The practical takeaway: use binary diff to detect and locate differences; use source-level diff to understand and review them.
CLI Tools for Binary File Comparison
Command-line tools are the fastest path for scripted or automated binary file
comparison. All of the following are available without installing anything on
macOS and most Linux distributions; Windows users get fc built in and can
install the others via WSL or Git Bash. For a broader look at Linux comparison commands,
see the complete Unix diff command guide.
cmp — the simplest binary compare
cmp
compares two files byte by byte. With no flags it exits 0 if identical,
1 if different, and reports the first differing byte:
cmp file1.bin file2.bin
To see all differing bytes with their offsets (not just the first), use
-l (lowercase L):
cmp -l file1.bin file2.bin | head
Output columns: byte offset (decimal), octal value in file1, octal value in file2.
Piping to head limits output when files have thousands of differences.
The exit code makes cmp ideal for scripts:
cmp -s file1 file2 && echo "identical" || echo "different".
The -s flag suppresses all output (silent mode) and only sets the exit code —
perfect for CI checks where you just need pass/fail.
diff with binary files
The standard diff command has limited value on raw binary files, but it is
useful for a quick existence check:
diff -q file1.bin file2.bin -q (quiet) reports only whether files differ, not the details. For actual
byte-level inspection, use cmp instead.
xxd + diff — human-readable hex diff
This is the most powerful CLI technique for binary diff because it
produces human-readable output without any additional tools. xxd converts
a binary file to a hex dump, and then standard diff compares those text
representations:
diff <(xxd file1.bin) <(xxd file2.bin)
Each line of xxd output contains an offset, 16 hex bytes, and the ASCII
representation. A unified diff of those lines shows exactly which 16-byte rows changed,
with the hex values visible directly. This is the closest you get to a readable
binary comparison without a GUI tool.
You can also dump to files first and diff those:
xxd file1.bin > a.hex
xxd file2.bin > b.hex
diff a.hex b.hex fc /b — Windows built-in binary compare
On Windows, fc (File Compare) supports binary mode with the /b
flag. No installation needed:
fc /b file1.bin file2.bin
Output shows each differing offset in hexadecimal with both byte values. If files are
identical, fc reports "FC: no differences encountered". For Windows folder
comparison workflows, see
how to find which files differ in Windows folders.
hexdump
hexdump (or hd on some systems) is an alternative to
xxd for generating hex representations. Combined with diff
or cmp, it produces similar results:
diff <(hexdump -C file1.bin) <(hexdump -C file2.bin)
The -C flag produces canonical output (same layout as xxd):
offset, hex bytes, ASCII printable characters. Either tool works; xxd
is often preferred because it can also reverse the process (xxd -r), which
is useful for patching.
GUI Tools for Binary Comparison
When you need to explore differences visually — scrolling through a hex editor with differences highlighted — GUI tools beat the command line. Here is a rundown of the most commonly used options for binary file comparison.
cmp, xxd, fc) are free and scriptable; GUI tools add interactive hex views. Only paid tools include full folder diff alongside binary comparison.Beyond Compare (Windows, macOS, Linux)
Beyond Compare is the most widely recommended commercial diff for binary files and every other file type. Its hex compare view shows both files side by side with differing bytes highlighted in red. It handles files up to several gigabytes, supports folder comparison, and integrates with version control systems. Price: from around $34 USD for a standard license. A 30-day free trial is available.
Strength: the combination of folder diff, text diff, and hex diff in one tool makes it the go-to for teams that need to compare many types of artifacts. Weakness: the cost is hard to justify for occasional use.
HxD (Windows, free)
HxD is a free, fast hex editor for Windows with a dedicated file compare feature. Open two files, go to Analysis → File Compare, and HxD highlights every differing byte in both panels. It handles very large files (multi-GB) efficiently because it streams data rather than loading everything into memory. For most Windows developers who need binary diff without paying for Beyond Compare, HxD is the first choice.
VBinDiff (cross-platform, free)
VBinDiff (Visual Binary Diff) is a terminal-based interactive hex diff tool. It displays
both files in a split screen, highlights differing bytes, and lets you navigate between
differences with keyboard shortcuts. It is available on Linux, macOS (via Homebrew:
brew install vbindiff), and Windows. The terminal UI means no GUI
dependencies — useful on servers or in Docker containers.
Note: development appears to have stalled since 2017, though the tool remains functional for binary comparison.
Guiffy (Windows, macOS, Linux)
Guiffy is a commercial diff and merge tool that includes binary comparison alongside text and folder diff. It is less well known than Beyond Compare but is a solid alternative with a similar feature set. Pricing typically starts around $30 for the Pro tier and $60 for the eXpert tier (verify current pricing on guiffy.com). Guiffy is particularly popular in teams already using it for text merges who want a single-tool workflow.
Hex Fiend (macOS, free)
Hex Fiend is the standard free hex editor on macOS. Open two files in Hex Fiend and use File → Compare to highlight byte-level differences. Like HxD on Windows, it handles large files well and is native to the platform (no X11 dependencies). Available on the Mac App Store and as a direct download. For macOS directory-level comparisons, see the macOS directory comparison guide.
010 Editor (Windows, macOS, Linux)
010 Editor is a professional hex editor that adds binary templates — structured definitions for hundreds of file formats (ELF, PE, ZIP, PNG, etc.) that let it display binary data as typed fields rather than raw bytes. Its Compare Files function works at the byte level and, when a template is applied, can also highlight which named fields changed. Pricing starts around $60 for a personal license, with commercial tiers higher (verify current pricing on sweetscape.com). Essential for anyone doing serious binary reverse engineering or format analysis.
Quick tool comparison
The table below summarises the key attributes of each GUI binary comparison tool:
| Tool | Platform | Price | Best For | Hex Editor |
|---|---|---|---|---|
| Beyond Compare | Windows, macOS, Linux | $34+ | Teams needing folder + text + hex diff in one tool | Yes |
| HxD | Windows only | Free | Fast routine binary diff on Windows; handles multi-GB files | Yes |
| VBinDiff | Linux, macOS, Windows | Free | Server / Docker use; no GUI dependencies required | Yes (TUI) |
| Guiffy | Windows, macOS, Linux | $30 / $60 | Teams already using Guiffy for text diff who want one tool | Yes |
| Hex Fiend | macOS only | Free | Native macOS hex editing; large file support via streaming | Yes |
| 010 Editor | Windows, macOS, Linux | $60+ | Binary reverse engineering; structured template overlays | Yes |
Platform-Specific Quickstarts
The second most common question: "How do I compare binary files on Windows / Linux / Mac?" Here is the fastest path on each platform.
Windows
Built-in, no installation:
fc /b file1.bin file2.bin For a visual comparison without spending money, download HxD from mh-nexus.de, open both files, and use Analysis → File Compare. HxD is portable (no installer required) and works on Windows 7 through 11.
If you have WSL or Git Bash installed, you also have access to cmp and
xxd — the same commands as Linux. WSL is generally the fastest path to
the full suite of Unix binary tools on Windows.
Linux
cmp and xxd are available on virtually every Linux distribution.
For a quick pass/fail check:
cmp -s file1.bin file2.bin && echo "identical" || echo "different" For a human-readable diff of all differences:
diff <(xxd file1.bin) <(xxd file2.bin) For interactive visual inspection, install VBinDiff:
sudo apt install vbindiff # Debian/Ubuntu
vbindiff file1.bin file2.bin For more Linux file comparison workflows, see the Linux compare files guide.
macOS
cmp is pre-installed on macOS. xxd is also available (it ships
with Vim). The same commands from the Linux section work identically on macOS because both
are POSIX-compliant.
cmp file1.bin file2.bin For a GUI tool, Hex Fiend is the obvious free choice (Mac App Store or hexfiend.com). Beyond Compare also has a native macOS version if you need the full commercial feature set. For folder-level comparison on macOS, the macOS directory comparison guide covers FileMerge and other options.
Best Practices: Hash First, Then Diff
Running a binary diff on two large files when you only want to know whether they differ is wasteful. The professional workflow is: hash first, diff only if hashes disagree.
Step 1: Compare hashes
SHA-256 is the standard for integrity verification. Compute a hash for each file and compare the outputs:
sha256sum file.bin
On macOS (where sha256sum may not be installed): shasum -a 256 file.bin.
On Windows PowerShell: Get-FileHash file.bin -Algorithm SHA256.
If the SHA-256 hashes match, the files are byte-for-byte identical. You are done — no diff needed. If they differ, proceed to step 2.
Step 2: Locate differences with cmp
Use cmp -l to get a list of all differing byte positions. For very large
files with millions of differences, pipe to wc -l first to gauge the
scale before viewing everything:
cmp -l file1.bin file2.bin | wc -l If only a handful of bytes differ (typical for a small patch or a timestamp embedding), pipe the full output to a pager:
cmp -l file1.bin file2.bin | less Step 3: Interpret offsets in context
Raw byte offsets are not meaningful on their own. To understand what a particular offset represents, you need to map it to the file's internal structure. Strategies:
- Use a hex editor with template support (010 Editor) to see which named field the offset falls inside — e.g., "PE optional header, SizeOfImage field".
- Check the file format specification. ELF, PE, ZIP, PNG, and most common formats have publicly documented structures. An offset near the beginning of a PE file is likely in the DOS header or PE header; near the end is likely in a section or the certificate table.
- Look for known patterns. If many bytes differ uniformly — every 4 bytes at regular intervals — it may be a timestamp or version number field rather than a meaningful code change.
- Ignore noise before investigating. Build timestamps, code-signing certificates, and debug info symbols routinely change between builds and are rarely interesting for a functional comparison.
Step 4: Correlate with source changes
Once you know which section of a binary changed (e.g., a specific ELF section or PE section), check the corresponding source code changes in that area. Use a text diff tool — or VS Code's diff viewer — to review the source-level changes that produced the binary delta.
Binary Diff in CI/CD Pipelines
One of the most underserved use cases for binary comparison is automated integrity validation inside CI/CD pipelines. Most teams run unit tests and linters but never verify that the build artifact itself matches expectations. Binary diff fills that gap.
cmp -l for byte-level diagnostics.Use case: reproducible build verification
A reproducible build produces a bit-for-bit identical binary from the same source,
toolchain, and environment. If two independent builds of the same commit differ, something
is non-deterministic — a timestamp, a random seed, a file ordering issue. cmp
catches this immediately:
cmp -s build-run1/app.bin build-run2/app.bin \
&& echo "PASS: builds are reproducible" \
|| (echo "FAIL: builds differ" && exit 1) Use case: artifact integrity check in GitHub Actions
The following GitHub Actions step downloads a reference artifact and compares it to the freshly built one. If they differ, the job fails:
- name: Verify binary artifact integrity
run: |
sha256sum dist/firmware.bin > actual.sha256
sha256sum -c expected.sha256 || {
echo "Artifact hash mismatch — binary changed unexpectedly"
cmp -l dist/firmware.bin reference/firmware.bin | head -20
exit 1
}
The workflow: first verify the hash (fast); if it fails, run cmp -l to
show which bytes changed (diagnostic); then exit 1 to fail the job and block the
deployment.
Use case: detecting binary bloat
Binary size regressions are easy to catch by comparing file sizes in CI, but if you want to understand where the size increase came from, compare the hex dumps of the before and after artifacts and look for new sections or padded regions. This is more useful for firmware or embedded targets where binary size is a hard constraint.
Use case: supply chain attack detection
In a secure supply chain workflow, you pin known-good checksums for all third-party
binaries (libraries, tools, installers) and verify them on every build. A mismatch
indicates either an upstream change (intended or otherwise) or a compromised artifact.
cmp -s with a pre-computed reference hash is the minimal implementation;
tools like cosign and SLSA attestations provide a more complete solution.
Where Text-Based Diff Tools Fit In
Text-based diff tools — including the Diff Checker extension — are not designed to compare raw binary files. The extension reads files using the browser's text APIs, which interpret bytes as characters. Arbitrary binary data contains null bytes, non-UTF-8 sequences, and control characters that will be misread, stripped, or cause the comparison to produce meaningless results.
That said, there are several binary-adjacent workflows where a text diff tool is exactly the right choice:
1. Diffing hex dump output
After running xxd on two binary files, you have two plain-text hex dump
files (.hex). Paste those into any text diff tool — including Diff Checker —
and you get a readable, color-coded comparison of which hex rows changed. This is a
practical and honest use of a text diff tool on binary data:
xxd file1.bin > a.hex
xxd file2.bin > b.hex
# Now paste a.hex and b.hex into your text diff tool The diff will show you exactly which 16-byte rows differ, with the hex values and ASCII representation visible. This workflow is particularly useful when you want to share a binary diff with a colleague who does not have a hex editor installed.
2. Diffing strings output
The strings command extracts printable ASCII sequences from a binary file
(at least 4 characters long by default). Diffing the strings output of
two binaries reveals added or removed string literals — function names, error messages,
version strings, file paths, URLs:
strings file1.bin > s1.txt
strings file2.bin > s2.txt
# Diff s1.txt and s2.txt in any text diff tool This is a coarse comparison — many string changes do not reflect meaningful functional changes — but it is a fast triage step that often surfaces the most interesting differences (a new URL, a changed version number, a new error message).
3. Source code review of binary handlers
After you identify a binary difference using cmp or a hex editor, the next
step is almost always reviewing the source code that writes or reads those bytes. Text
diff tools — including Diff Checker — are well suited for comparing two versions of a
binary parser, encoder, serializer, or firmware module. For example:
- Comparing the C source of a firmware module before and after a patch.
- Diffing the Python struct-packing code that writes a binary protocol frame.
- Reviewing changes to a file format writer that produced unexpected binary output.
4. Base64-encoded payload diffs
Binary data embedded in JSON, XML, or YAML is commonly base64-encoded. If two
configuration files or API responses contain differing base64 payloads, you can
diff the base64 strings directly as text — you will not be able to read the
differences meaningfully, but you can at least confirm that the encoded content
changed and by how much. Decoding both strings and running cmp on the
decoded files gives the authoritative byte-level answer.
When NOT to Use Binary Diff
Binary diff is precise but deliberately low-level. For several common file types, a higher-level tool understands the format better and gives more useful output:
PDF files
PDFs are binary, but their content is structured — page objects, fonts, images, cross-reference tables. A byte-level diff of two PDFs that differ only in a single word change will show thousands of byte differences because PDF rebuilds its cross-reference table on every save. Use a PDF-aware comparison tool (Adobe Acrobat's Compare Documents, pdf-diff, or Draftable) that understands page content rather than raw bytes.
Image files (PNG, JPEG, WebP)
Image formats store pixel data with compression. A single pixel change can produce a
completely different compressed byte stream. Use an image diff tool (ImageMagick's
compare, Pixelmatch, or perceptual hash comparison) that operates at the
pixel level rather than the byte level.
Structured data stored as binary (SQLite, Parquet, Arrow)
SQLite databases and column-oriented data formats (Parquet, Arrow, Feather) have rich internal structure. A binary diff will tell you bytes changed but not which rows or columns. Use database-level comparison (SQL queries, schema diff tools like MySQL database compare tools) or format-specific libraries to extract and compare the logical content.
Compressed archives (ZIP, tar.gz)
Archive formats embed timestamps, compression parameters, and sometimes file ordering that varies between creation runs. Even if the contained files are identical, two archives created at different times will likely differ at the byte level. Extract the archives and compare the individual files rather than the archive as a whole.
Office documents (DOCX, XLSX, PPTX)
Modern Office formats are ZIP archives containing XML. A binary diff is nearly useless. Use Word's built-in Compare Documents, or extract the XML and use a text diff tool. See the Word document comparison guide for all available options.
JSON with binary fields
If your "binary" data is actually a JSON or YAML file with embedded binary values (base64, hex strings), the right tool is a JSON-aware diff tool, not a hex editor. JSON diff tools understand the document structure and can show you which key changed rather than which byte offset changed.
Frequently Asked Questions
What is the difference between binary diff and text diff?
A text diff splits files into lines on newline characters and compares those lines as strings, so it understands context but breaks on null bytes or non-UTF-8 data. A binary diff reads both files as raw byte streams and reports the exact byte offset and old/new values for every divergence — making it the only reliable approach for executables, firmware images, PDFs, and other non-text formats.
How do I compare two binary files on Windows?
The fastest path on Windows is the built-in fc command with the /b
flag: fc /b file1.bin file2.bin. It reports each differing offset in
hexadecimal with both byte values. For a visual side-by-side hex view, install HxD (free,
portable) and use Analysis → File Compare. If you have WSL or Git Bash, you also get
cmp and xxd.
How do I compare binary files in Linux?
Use cmp for a quick pass/fail check
(cmp -s file1 file2 && echo identical) and cmp -l to list
every differing byte offset in octal. For a human-readable hex diff, pipe both files
through xxd: diff <(xxd file1.bin) <(xxd file2.bin).
GNU diffutils
documents the full set of binary-related options.
Can Diff Checker compare binary files?
No — Diff Checker is a text and code diff tool and is not designed for raw binary files.
The browser reads inputs as text, so null bytes and non-UTF-8 sequences will be mangled.
Use cmp, xxd, HxD, or Beyond Compare for raw binary comparison,
then use Diff Checker for the source code, hex dump output, or strings extracted from
those binaries.
What is the best free tool for binary file comparison?
On the command line, cmp (Linux/macOS) and fc /b (Windows) are
free, ship with the OS, and cover most needs. For a free GUI hex-compare experience, HxD
is the standard on Windows and Hex Fiend on macOS — both handle multi-gigabyte files
efficiently. VBinDiff is the best free cross-platform option for terminal-only environments
like servers or Docker containers.
Conclusion
Effective binary comparison is a two-step process: first, detect that
files differ (hashing or cmp -s); second, understand what changed (hex dump
diff, GUI hex editor, or — for format-aware formats — a higher-level tool). The CLI tools
cmp, xxd, and fc /b cover the majority of
everyday binary diff needs on all platforms without any installation.
For interactive exploration, HxD (Windows) and Hex Fiend (macOS) are the free choices;
Beyond Compare and 010 Editor are the paid choices for teams that need more power.
For automated environments, the diff for binary files workflow is
simple: compute SHA-256 hashes in CI, compare them, and call cmp -l
only when a mismatch requires diagnosis. Embedding this check in GitHub Actions or
any other CI system adds meaningful integrity validation with a single shell command.
Once a binary difference is located and understood, the next step is almost always reviewing the source code that produced it. That is where a text diff tool re-enters the workflow — not as a replacement for a hex editor, but as the right tool for the source-code-review phase.
Review the Source Code Behind the Binary Change
After locating a binary mismatch with cmp or a hex editor, the real
investigation happens in the source code. Diff Checker lets you paste two versions
of a C file, Python module, firmware header, or binary-format handler and instantly
see every line that changed — with syntax highlighting for 20+ languages.
It is also useful for diffing hex dump output: paste the xxd output of
two files as plain text and see exactly which hex rows differ in a color-coded,
side-by-side view.
Note: Diff Checker is a text and code diff tool. It does not compare
raw binary files — use cmp, HxD, or Beyond Compare for that. Use
Diff Checker for the source code, hex dumps, and string output that explain the
binary difference.