How-To Guide

    How to Compare Binary Files on Windows, Mac, and Linux

    Check whether two binary files are identical, find the exact bytes that differ with fc /b and cmp, and read a hex diff without being fooled by shifted bytes.

    Published October 28, 2026Updated October 28, 20267 min read
    Mehrab Ali

    Author

    Mehrab Ali

    Founder & Executive Lead, ARCED International

    Founder of ARCED Foundation, ARCED International, and Solutions of Things Lab (SoTLab). Built FolderManifest to help teams protect file integrity and stay audit-ready.

    Quick Answer

    To compare binary files on Windows, run fc /b file1.bin file2.bin in Command Prompt; on Linux or macOS, run cmp file1.bin file2.bin. Both are built in and report the byte offsets where the files differ. If you only need to know whether two files are identical, compare their SHA-256 hashes instead.

    Text diff tools don't help here: binary files have no meaningful lines, so diff just says Binary files differ. The commands below were run on Windows 11 and in a Bash shell, with output shown exactly as printed.

    Step 1: Check If the Binary Files Are Identical

    Most of the time the real question is “is this the same file?”: a firmware image, a build artifact, a backup copy, a download. A hash answers that in one line, and it works on files of any size.

    # Windows PowerShell: True if identical
    (Get-FileHash a.bin).Hash -eq (Get-FileHash b.bin).Hash
    
    # Linux
    sha256sum a.bin b.bin
    
    # macOS
    shasum -a 256 a.bin b.bin

    Matching SHA-256 hashes mean the files are byte-for-byte identical. Different hashes tell you that they differ, but not where. For a no-install check, the free Compare Files tool hashes two files up to 10 MB each in memory on our server, never stores them, and gives you the same identical-or-different answer. More on hashing in our Get-FileHash guide.

    Step 2 on Windows: fc /b and comp

    fc /b lists every differing byte

    C:\> fc /b a.bin b.bin
    Comparing files a.bin and B.BIN
    00000003: 44 78
    00000009: 4A 79

    Each line is the offset (hexadecimal, counted from 0), then the byte in the first file, then the byte in the second file. Here byte 3 is 0x44 in a.bin and 0x78 in b.bin. Other messages you will see:

    • FC: no differences encountered: the files are identical.
    • FC: C.BIN longer than a.bin: the shared part matches (or its differences are listed above), and one file has extra bytes at the end.

    fc returns exit code 0 for identical files and 1 when they differ, so you can use it in batch scripts with if errorlevel 1. In PowerShell, type fc.exe: plain fc is an alias for Format-Custom and will not compare anything.

    comp stops after 10 differences

    C:\> comp a.bin b.bin /m
    Comparing a.bin and b.bin...
    Compare error at OFFSET 3
    file1 = 44
    file2 = 78
    Compare error at OFFSET 9
    file1 = 4A
    file2 = 79

    /m skips the “Compare more files (Y/N)?” prompt. comp gives up after 10 mismatches and refuses files of different lengths with Files are different sizes, so fc /b is usually the better choice.

    PowerShell, when you need custom output

    $x = [IO.File]::ReadAllBytes("$PWD\a.bin")
    $y = [IO.File]::ReadAllBytes("$PWD\b.bin")
    for ($i = 0; $i -lt [Math]::Min($x.Length, $y.Length); $i++) {
      if ($x[$i] -ne $y[$i]) { '{0:X8}: {1:X2} {2:X2}' -f $i, $x[$i], $y[$i] }
    }

    This prints the same format as fc /b and is easy to change, for example to export to CSV. It loads both files into memory, so keep it for files of a few hundred MB or less.

    Step 2 on Linux and macOS: cmp

    $ cmp a.bin b.bin
    a.bin b.bin differ: byte 4, line 1
    
    $ cmp -l a.bin b.bin
     4 104 170
    10 112 171
    
    $ cmp -s a.bin b.bin && echo same || echo different
    different
    • Plain cmp stops at the first difference. Some versions say char 4 instead of byte 4.
    • cmp -l lists every differing byte: position (decimal, counted from 1), then the two values in octal. 104 octal is 0x44, the same byte fc reported at offset 3.
    • cmp -s prints nothing and only sets the exit code: 0 identical, 1 different, 2 error.
    • cmp -l a.bin b.bin | wc -l counts how many bytes differ.

    When one file is longer, cmp adds cmp: EOF on a.bin after byte 10.

    Step 3: See the Differences Side by Side with a Hex Diff

    Offsets alone are hard to read. Dump both files to hex and diff the dumps to see each change in context (Bash or zsh; xxd ships with Vim and is preinstalled on macOS):

    $ diff <(xxd a.bin) <(xxd b.bin)
    1c1
    < 00000000: 4142 4344 4546 4748 494a   ABCDEFGHIJ
    ---
    > 00000000: 4142 4378 4546 4748 4979   ABCxEFGHIy

    Watch for shifted bytes

    xxd prints fixed 16-byte rows. If one byte was inserted or deleted, every row after it shifts and the diff marks the rest of the file as changed. Hex diffs, fc /b, and cmp -l all compare byte N with byte N, so they work best on same-length files with patched bytes.

    In Python, filecmp.cmp('a.bin', 'b.bin', shallow=False) returns True only when the contents match; the default shallow=True can return True from file size and modification time alone.

    GUI Hex Compare Tools

    If you compare binaries often, a visual hex compare is easier on the eyes. Beyond Compare has a Hex Compare view, and WinMerge (free, Windows) can show binary files in a hex view. Our FolderManifest vs Beyond Compare and FolderManifest vs WinMerge pages cover where each one fits. For reverse engineering (what changed between two versions of an executable), byte diffs aren't enough; dedicated binary-diffing tools compare functions instead.

    Comparing Many Binary Files: Builds, Backups, Migrations

    Running fc /b file by file breaks down once you have a folder of DLLs, images, or archives to check against another copy. You need to know which files are missing, which were added, and which changed content, even when names and sizes match.

    FolderManifest builds a folder manifest: every file with its path, size, dates, and a SHA-256 hash. Compare two folders, or check a copy against a saved manifest, and it lists exactly which files were added, removed, or changed. It runs locally on Windows 10/11, macOS, and Linux, so large binaries never leave your machine. It tells you which files changed, not which bytes inside them; use fc /b or cmp -l on those for the byte detail.

    Want to try it on two folders first? The free Folder Compare tool shows missing, added, and changed files side by side, and our guide to comparing two folders on Windows covers the built-in options.

    Frequently Asked Questions

    How do I compare two binary files on Windows?

    Open Command Prompt and run fc /b file1.bin file2.bin. It prints every differing byte as a hex offset followed by the two byte values, or "FC: no differences encountered" when the files match. In PowerShell type fc.exe, because fc on its own is an alias for Format-Custom.

    How do I compare binary files on Linux or macOS?

    Run cmp file1.bin file2.bin. It stops at the first difference and reports its byte position, prints nothing when the files are identical, and returns exit code 0 (same) or 1 (different). Add -l to list every differing byte.

    Why does diff say "Binary files differ"?

    diff compares lines of text. When it detects binary content it only reports that the files differ, without showing where. Use cmp -l for byte positions, or dump both files to hex with xxd and diff the dumps.

    What is the fastest way to check if two binary files are identical?

    Compare their hashes. On Windows: (Get-FileHash a.bin).Hash -eq (Get-FileHash b.bin).Hash returns True or False. On Linux: sha256sum a.bin b.bin; on macOS: shasum -a 256 a.bin b.bin. Matching SHA-256 hashes mean the files are byte-for-byte identical.

    Can I compare binary files online?

    Yes. FolderManifest’s free Compare Files tool takes two files up to 10 MB each, computes their SHA-256 hashes in memory on our server without storing them, and tells you whether they are identical. It does not show which bytes differ; use fc /b or cmp -l for that.

    Why does a hex diff show almost every line as different?

    A hex dump has fixed 16-byte rows, so a single inserted or deleted byte shifts everything after it and every following row looks changed. Hex diffs are reliable for same-length files with patched bytes; for insertions use a tool that aligns byte sequences.

    Check Whole Folders of Binaries in One Pass

    Record every file with its SHA-256 hash, then check any later copy against it. Windows, Mac, and Linux. 7-day free trial, no card required, 30-day money-back guarantee.

    Continue Learning