Skip to content
SimpleTools24

How to Compare Two Binary Files and Find Differences

By SimpleTools24Published 4 min read

To compare two binary files, start by checking whether they're identical: compare their sizes and a checksum such as SHA-256. If they differ, use a byte-by-byte comparison to find where: cmp on macOS and Linux, fc /b on Windows, or a hex viewer with a compare mode that shows the differing bytes side by side. Text diff tools aren't designed for this, because binary files don't have meaningful lines.

Step 1: Are the Files Identical?

Compare Sizes

Different sizes means different files, immediately. Same size proves nothing, though; firmware images and disk images often have fixed sizes.

Compare Checksums

A cryptographic hash condenses a file into a short fingerprint. If even one bit differs, the hash changes completely.

bash
# macOS / Linux
shasum -a 256 old.bin new.bin
sha256sum old.bin new.bin
powershell
# Windows PowerShell
Get-FileHash .\old.bin, .\new.bin -Algorithm SHA256

Matching SHA-256 hashes mean the files are, for all practical purposes, identical. This is also how you verify a download against the checksum published by its source. MD5 is still shown by many sites; it's fine for spotting accidental corruption, but not for guarding against deliberate tampering.

Step 2: Find Where They Differ

cmp (macOS and Linux)

bash
cmp old.bin new.bin
# old.bin new.bin differ: byte 4097, line 12

cmp stops at the first difference and reports its position, counted from 1. To list every differing byte:

bash
cmp -l old.bin new.bin | head

Each line shows the position (decimal, from 1) and the two byte values in octal, which surprises people expecting hex. If there are thousands of differences, the output gets long fast; pipe it to wc -l to count them.

fc /b (Windows Command Prompt)

bat
fc /b old.bin new.bin

fc /b lists each differing offset in hex with both bytes. If the files are different lengths, it reports which one is longer after the common part.

Hex Dumps Plus a Text Diff

A trick that works everywhere: convert both files to hex dumps and diff the text.

bash
diff <(xxd old.bin) <(xxd new.bin)

This shows changes in context, with offsets and ASCII columns. It falls apart if bytes were inserted or removed, because every following line shifts and appears different.

Insertions vs Changes

Byte-by-byte comparison assumes data stays at the same offsets. That's true for in-place changes, like a patched value in firmware or a flipped bit from corruption. But if a single byte is inserted near the start, everything after it moves, and a simple compare reports almost the whole file as different.

Signs of an insertion or deletion:

  • The file sizes differ by a small amount.
  • After the first difference, nearly every byte differs.
  • In a hex view, the same content appears shifted by a few positions.

For those cases, a dedicated binary diff tool that aligns sequences (VBinDiff, or the comparison features of full hex editors) does a better job.

Choosing a comparison method
QuestionBest method
Are these files exactly the same?SHA-256 hash
Did my download arrive intact?Hash against the published checksum
Where is the first difference?cmp, fc /b, or a compare view
How many bytes changed in place?cmp -l count, or a compare view
What changed, with context?Side-by-side hex comparison
Data inserted or removed?Alignment-aware binary diff tool

Comparing Files in the Browser

If you'd rather see the differences than read terminal output, you can compare two files in a binary viewer:

  1. Open the first file, then choose Compare files and select the second.
  2. The summary tells you whether the files are identical, how many bytes differ, and the offsets of the first and last differences.
  3. The comparison shows the differing bytes side by side in hex, and buttons jump to the next or previous difference.

Both files are read in your browser, up to 64 MB each, and neither is uploaded. That makes it suitable for firmware, save files or documents you'd rather not send anywhere. If you're not used to reading the hex columns, how to read a hex dump explains offsets and byte values.

Common Reasons Two "Identical" Files Differ

  • Embedded timestamps. Archives, executables and documents often record the time they were created, so rebuilding the same content produces a different file.
  • Metadata. Photos re-saved by a phone or editor gain or lose EXIF data.
  • Line endings. A "text" file converted between Windows and Unix line endings differs in every line; see binary vs text files.
  • Padding. Fixed-size images and firmware may have different filler bytes (00 vs FF) in unused space.
  • Corruption. Isolated single-byte differences in otherwise identical files often point to transfer or storage errors.

Frequently Asked Questions

Can I compare two large files quickly?

Hashing is fastest for a yes/no answer, since it reads each file once. cmp is also fast because it stops at the first difference unless you ask for all of them.

Why does cmp show octal numbers?

That's its traditional output format. Convert the values, or use fc /b or a hex viewer if you prefer hexadecimal.

Can text diff tools compare binary files?

Not directly. Convert both files to hex dumps first, or use a tool designed for binary comparison.

Two files have the same hash but different names. Are they the same?

Yes. Hashes depend only on content; names and dates aren't part of it.

Summary

Hash first to answer "same or different", then use cmp, fc /b or a side-by-side hex comparison to find where. Watch for shifted data after insertions, which makes everything after the change look different.