CMD Simulator
File Managementcomp

COMP Command Guide - Compare Two Files Byte by Byte in Windows

Learn how to use the comp command to compare the contents of two files or sets of files byte by byte in Windows Command Prompt. Includes syntax, examples, troubleshooting, and best practices.

Rojan Acharya··Updated Feb 12, 2026
Share

The comp command is a Windows Command Prompt utility that compares the contents of two files or sets of files byte by byte, displaying differences and verifying file integrity. Use comp file1 file2 to check if files are identical, or add /d to display differences in decimal format for detailed analysis of file discrepancies, data validation, and quality assurance testing.

Whether you're verifying backup integrity, checking file transfers for corruption, validating software builds, or debugging data processing issues, the comp command provides low-level file comparison capabilities essential for quality assurance and data integrity verification. IT professionals, developers, and system administrators rely on comp for file validation, corruption detection, and ensuring exact file copies across systems.

This comprehensive guide covers comp syntax, comparison options, practical examples for binary and text files, troubleshooting tips, comparison with fc command, related file utilities, and frequently asked questions. By the end, you'll confidently use comp for file integrity verification, quality assurance, and data validation tasks from the command line.

What Is the Comp Command?

The comp command has been part of Windows and MS-DOS for decades, providing fundamental file comparison functionality at the byte level. Unlike text-based comparison tools, comp performs binary comparison, making it suitable for verifying exact file copies regardless of file type—text documents, executables, images, databases, or any binary data.

Comp reads both files byte by byte and reports any differences found. When files are identical, comp confirms they match. When differences exist, comp reports the location and optionally displays the differing byte values. This makes comp essential for:

  • Integrity verification – Confirming files haven't been corrupted during transfer or storage
  • Backup validation – Verifying backup copies match original files exactly
  • Quality assurance – Ensuring file processing or conversion produces expected results
  • Version comparison – Detecting any changes between file versions

The command works in Command Prompt (CMD), PowerShell (with some limitations), and is available in all Windows versions including Windows 11, Windows 10, Windows 8, Windows 7, and Windows Server editions. For text file comparison with more readable output, Windows also provides the fc (file compare) command.

Comp Command Syntax

The basic syntax for the comp command is:

comp [data1] [data2] [/d] [/a] [/l] [/n=number] [/c] [/off[line]]

Parameters and Switches

ParameterDescription
data1Specifies the location and name of the first file or set of files to compare
data2Specifies the location and name of the second file or set of files to compare
/dDisplay differences in decimal format (default is hexadecimal)
/aDisplay differences as ASCII characters
/lDisplay line numbers where differences occur (for text files)
/n=numberCompare only the first specified number of lines
/cCase-insensitive comparison (ignores case differences in ASCII text)
/off[line]Process files with offline attribute set
/?Display help information

Common Usage Patterns

Basic comparison:

comp file1.txt file2.txt

Display differences in decimal:

comp file1.bin file2.bin /d

ASCII character display:

comp log1.txt log2.txt /a

Case-insensitive text comparison:

comp doc1.txt doc2.txt /c

If you omit file specifications, comp prompts interactively for filenames. Wildcards (* and ?) are supported for comparing multiple files.

Understanding Comp Output

Comp provides different types of output depending on comparison results:

Files Are Identical

Comparing file1.txt and file2.txt...
Files compare OK

This confirms both files contain identical byte-for-byte content.

Files Differ (Hexadecimal Display - Default)

Comparing file1.txt and file2.txt...
Compare error at OFFSET 15
file1 = 41
file2 = 42
  • OFFSET – Byte position where difference occurs (hexadecimal)
  • file1/file2 values – Byte values in hexadecimal at that position

Files Differ (Decimal Display with /d)

Comparing file1.bin and file2.bin...
Compare error at OFFSET 21
file1 = 65
file2 = 66

Decimal format is more readable for human interpretation than hexadecimal.

Files Differ (ASCII Display with /a)

Comparing log1.txt and log2.txt...
Compare error at OFFSET 15
file1 = A
file2 = B

ASCII display shows actual characters, making text file comparison more intuitive.

File Size Mismatch

Comparing file1.dat and file2.dat...
Files are different sizes

When files have different lengths, comp reports size mismatch and exits without byte-by-byte comparison.

Practical Comp Command Examples

Compare Two Text Files

Basic comparison of two text documents:

comp document1.txt document2.txt

If files are identical, output shows "Files compare OK". If different, comp displays the offset of the first 10 mismatches by default.

Compare Binary Files with Decimal Output

Compare two binary files and display differences in decimal format:

comp program.exe backup_program.exe /d

Decimal format is easier to interpret than hexadecimal for manual analysis. Useful for verifying executable integrity after file transfers.

Compare with ASCII Character Display

Compare text files showing differences as readable characters:

comp config_original.ini config_modified.ini /a

ASCII display makes it easy to see exactly which characters differ between configuration files.

Case-Insensitive Text Comparison

Compare text files ignoring case differences:

comp readme.txt README.TXT /c

The /c parameter treats uppercase and lowercase letters as identical. Useful when case variations don't indicate actual file differences.

Compare First N Lines Only

Compare only the first 100 lines of large files:

comp largefile1.log largefile2.log /n=100

This limits comparison to specified number of lines, speeding up checks on large files when only the beginning matters (like log file headers).

Compare with Line Numbers

Display line numbers for differences in text files:

comp source_v1.cpp source_v2.cpp /l

The /l parameter shows line numbers where differences occur, making it easier to locate changes in source code or text documents.

Compare Multiple Files with Wildcards

Compare all .txt files in current directory against backup folder:

comp *.txt C:\Backup\*.txt

Comp processes each matching file pair. Useful for batch validation of multiple file backups or transfers.

Interactive Comparison

Run comp without parameters for interactive mode:

comp

Comp prompts:

Name of first file to compare: file1.txt
Name of second file to compare: file2.txt

Useful when you want comp to prompt for filenames rather than typing them on the command line.

Compare Files in Different Directories

Verify a copied file matches the original:

comp C:\Original\data.db D:\Backup\data.db /d

Full paths ensure comp compares the correct files across different locations.

Validate File Transfer Integrity

After copying important files, verify integrity:

comp source.iso \\server\share\destination.iso

Confirms network file transfers completed without corruption. Critical for ISO images, databases, and other files where any corruption renders them unusable.

Common Use Cases for the Comp Command

  1. Verify backup integrity – After backing up critical files, use comp to confirm backup copies are byte-for-byte identical to originals. Even one corrupted byte can make files unusable.

  2. Validate file transfers – After copying files (especially over networks), use comp to detect any corruption introduced during transfer. Essential for large files like ISOs, VMs, or databases.

  3. Check software build consistency – Compare compiled executables or libraries from different builds to ensure identical output, verifying reproducible builds and detecting unexpected changes.

  4. Detect file corruption – Periodically compare current files against known-good backups to detect bit rot, disk errors, or malware modifications that changed file contents.

  5. Quality assurance testing – Verify file processing tools (converters, compressors, encrypters) produce expected output by comparing processed files against reference files.

  6. Version control verification – Before committing files to version control, compare against previous versions to ensure only intended changes were made.

  7. Data migration validation – When migrating data between systems, use comp to verify files were transferred completely and accurately without corruption or truncation.

  8. Configuration file auditing – Compare current system configuration files against baseline configurations to detect unauthorized modifications or drift from standards.

  9. Disaster recovery testing – Validate restored files from backups match original files exactly, ensuring backup and restore procedures work correctly.

  10. Forensic analysis – Compare suspicious files against known-good versions to detect malware modifications, rootkit changes, or unauthorized file replacements.

  11. Source code comparison – Quickly verify source files between branches or after merges match expected versions, catching unintended changes before compilation.

  12. Binary patch verification – After applying patches or updates to executables or DLLs, compare against expected post-patch files to confirm successful application.

Tips and Best Practices

  1. Use /d for human-readable output – Decimal format (/d) is easier to interpret than default hexadecimal for manual review. Hexadecimal is better for technical analysis.

  2. Combine /a and /l for text files – Use both parameters for text file comparison: comp file1.txt file2.txt /a /l shows differences as characters with line numbers, making changes easy to locate.

  3. Verify file sizes first – If files have different sizes, they obviously differ. Use dir file1 file2 to check sizes before running comp on large files to save time.

  4. Redirect output for large comparisons – Save comp output to file for review: comp large1.dat large2.dat /d > comparison.txt. Comp stops after 10 mismatches by default, so output files capture all displayed differences.

  5. Use fc for better text comparison – For text files where you need to see actual content differences (not just byte positions), use fc /n file1.txt file2.txt instead. Comp is better for binary files.

  6. Script with errorlevel – Comp sets errorlevel 0 (files match) or 1 (files differ). Use in batch scripts: comp file1 file2 > nul && echo Files match || echo Files differ.

  7. Test critical transfers immediately – After copying important files, run comp before deleting originals. Detect corruption while you still have source files.

  8. Compare small samples of large files first – Use /n=100 to compare just the beginning of multi-GB files. If headers/initial data differ, no need to compare entire files.

  9. Wildcards for batch validation – When backing up many files, use comp C:\Source\*.* D:\Backup\*.* to validate all files at once. Review output for any mismatches.

  10. Case-insensitive for text when appropriate – Use /c when comparing text files from different sources (Windows vs Linux) where case may vary but content is semantically identical.

  11. Document comparison results – For compliance or quality assurance, redirect comp output to dated log files: comp data.db backup.db /d > compare_%date%.log.

  12. Alternative tools for complex needs – For advanced comparison (showing what changed, not just where), consider fc for text or third-party tools like Beyond Compare or WinMerge.

Troubleshooting Common Issues

"Invalid number of parameters" Error

Problem: Comp displays "Invalid number of parameters" when you run the command.

Cause: Missing required file parameters, or incorrect syntax.

Solution:

  • Comp requires two file specifications: comp file1 file2
  • Check for typos in filenames or paths
  • Enclose paths with spaces in double quotes: comp "C:\My Documents\file.txt" "D:\Backup\file.txt"
  • Verify files exist before comparing: dir file1 and dir file2

Prevention: Always specify both files to compare. Use Tab completion to avoid typos in filenames.

"Files are different sizes"

Problem: Comp reports files have different sizes and exits without detailed comparison.

Cause: Files have different lengths—one is larger than the other.

Solution:

  • This is informational, not an error. Files definitely differ if sizes don't match
  • Use dir file1 file2 to see exact size difference
  • Check if one file was truncated during transfer
  • Verify you're comparing the intended files (not wrong versions)

Prevention: Check file sizes before running comp on large files to save time.

"Too many errors" Warning

Problem: Comp displays "Too many errors" and stops comparing before reaching end of file.

Cause: Comp stops after 10 mismatches by default to prevent excessive output on completely different files.

Solution:

  • This indicates files are significantly different, not just minor variations
  • If you need all differences, redirect to file: comp file1 file2 /d > full_comparison.txt
  • For text files, consider using fc instead for more detailed difference reporting
  • Verify you're comparing related files (not completely different files)

Prevention: Use comp for verifying identical copies. For detailed change analysis, use fc or diff tools.

Comparison Hangs or Takes Very Long

Problem: Comp command appears stuck or takes much longer than expected.

Cause: Comparing very large files (multi-GB), files on slow network drives, or files on failing disks.

Solution:

  • Be patient—comp must read both files completely for byte-by-byte comparison
  • Monitor disk activity in Task Manager to verify comp is progressing
  • Press Ctrl+C to cancel if needed
  • For large files, compare small sections first: comp /n=1000 file1 file2
  • Copy network files locally before comparing for much faster operation

Prevention: Check file sizes before comparing. Consider alternatives like hash comparison (certutil) for very large files.

Comp Shows Differences but Files Are Identical

Problem: Comp reports differences but files appear identical when opened.

Cause: Hidden metadata differences, line ending differences (CRLF vs LF), or embedded timestamps in file formats.

Solution:

  • Files may be functionally identical but have different binary content
  • Line endings: Windows (CRLF: 0D 0A) vs Unix (LF: 0A) cause byte differences
  • Check file metadata: timestamps, hidden attributes
  • For text files with line ending differences, use fc /w (ignore whitespace)
  • Some file formats embed timestamps or unique IDs even when content is identical

Prevention: Understand file format characteristics. Use format-specific comparison tools for complex files (e.g., diff tools for source code).

Access Denied Error

Problem: Comp fails with "Access denied" error.

Cause: Insufficient permissions to read one or both files, or files are locked by another process.

Solution:

  • Run Command Prompt as Administrator if comparing system files
  • Check file permissions with icacls filename
  • Close applications that may have files open
  • For network files, verify read permissions on the share
  • Try copying files to a local folder and comparing locally

Prevention: Ensure read access to both files before running comp. Close files in applications before comparing.

Related Commands

fc – File Compare (Advanced Text Comparison)

While comp performs byte-by-byte binary comparison, fc (File Compare) provides more sophisticated text file comparison with context, showing actual lines that differ instead of just byte positions.

When to use fc: Text files where you want to see what changed, not just where changes occurred. FC shows actual line content.

When to use comp: Binary files, quick verification that files are identical, or when byte-level precision is needed.

Example: fc /n file1.txt file2.txt shows differences with line numbers and context.

fc – Binary Mode

FC can also compare binary files: fc /b file1.exe file2.exe performs byte-level comparison similar to comp but with different output format.

Advantage: FC binary mode shows more differences before stopping (default 100 vs comp's 10).

certutil – Hash-Based Comparison

For large files, hash comparison is faster than byte-by-byte: compute hashes of both files and compare hashes instead of file contents.

Example:

certutil -hashfile file1.iso SHA256 > hash1.txt
certutil -hashfile file2.iso SHA256 > hash2.txt
fc hash1.txt hash2.txt

Advantage: Much faster for multi-GB files. If hashes match, files are identical (cryptographically certain).

robocopy – Copy with Verification

robocopy can copy files and verify integrity using hash checking: robocopy C:\Source D:\Dest /MIR /ZB /R:3 /W:5 /V /ETA.

Advantage: Built-in integrity verification during copy operations. No separate comparison step needed.

xcopy – Copy with Verification

xcopy with /V verifies files after copying: xcopy C:\Source\*.* D:\Dest\ /V /E /Y.

Advantage: Automatic verification as part of copy operation.

find / findstr – Search for Differences

Combine comp with findstr to extract specific information from comparison output:

comp file1.txt file2.txt /a | findstr "Compare error"

Use case: Parse comp output in scripts to count differences or extract specific mismatch information.

diff (Third-Party) – Advanced Text Comparison

Unix-style diff tools (available via Git Bash, Cygwin, or WSL) provide industry-standard text comparison with unified diff format, patch generation, and more features than comp or fc.

Example: diff -u file1.txt file2.txt shows unified diff format common in version control.

Frequently Asked Questions

What does comp command do?

Comp compares two files byte by byte and reports whether they are identical or different. If differences exist, comp displays the byte offset and values where files differ. Use comp file1 file2 to verify files are exact copies. Comp works with any file type—text, binary, executables, images, databases.

How do I compare two files in CMD?

Use comp file1.txt file2.txt to compare files in Command Prompt. Add /d for decimal output: comp file1 file2 /d. For text files, add /a to display differences as ASCII characters: comp file1.txt file2.txt /a /l. If files match, comp displays "Files compare OK".

What is the difference between comp and fc?

Comp performs byte-by-byte binary comparison showing byte offsets and values. FC (File Compare) provides text-aware comparison showing actual line content that differs. Use comp for binary files or quick verification; use fc for text files when you want to see what changed, not just where.

Can comp compare folders?

No, comp only compares individual files or file sets using wildcards. To compare folder contents, use comp C:\Folder1\*.* C:\Folder2\*.* to compare all matching files. For full directory comparison including subdirectories, use robocopy /L (list mode) or third-party tools.

How do I stop comp after a certain number of differences?

Comp automatically stops after 10 mismatches by default to prevent excessive output. This behavior is built-in and cannot be changed. To capture more differences, redirect output to a file: comp file1 file2 /d > results.txt. For unlimited difference reporting, use fc instead.

Does comp work with binary files?

Yes, comp is designed for byte-by-byte comparison and works perfectly with binary files (executables, images, databases, archives). Use /d for decimal output: comp program.exe backup.exe /d. For large binary files, consider hash comparison (certutil) for faster verification.

How can I compare files and ignore line endings?

Comp cannot ignore line ending differences (CRLF vs LF) as it compares byte-by-byte. Use fc /w (ignore whitespace including line endings) for text files. Alternatively, normalize line endings before comparison using text editors or conversion tools.

Can I use comp in batch scripts?

Yes, comp is commonly used in validation scripts. Check errorlevel: comp file1 file2 > nul && echo Match || echo Differ. Errorlevel 0 = files match, 1 = files differ, 2 = error. Example script:

@echo off
comp source.dat backup.dat /d > comp.log
if %errorlevel%==0 (echo Backup verified) else (echo Backup differs)

Why does comp show hexadecimal values?

Comp displays differences in hexadecimal by default because it's the standard for low-level binary analysis. Use /d for decimal format or /a for ASCII characters. Example: comp file1 file2 /d shows differences as decimal numbers (0-255) instead of hex (00-FF).

How do I compare files case-insensitively?

Use the /c parameter: comp file1.txt file2.txt /c. This treats uppercase and lowercase ASCII characters as identical. Useful when comparing text files from different sources where case may vary but content is semantically the same.

What does "Compare error at OFFSET" mean?

This indicates the byte position where files first differ. OFFSET is in hexadecimal by default. Example: "Compare error at OFFSET 1A" means byte position 26 (decimal) differs. The following lines show the actual byte values at that position in each file.

Can comp verify file integrity after transfer?

Yes, comp is excellent for integrity verification. After copying files, run comp source.file destination.file to confirm byte-for-byte identical copy. If comp reports "Files compare OK", transfer was successful without corruption. Critical for important files like databases, backups, or ISOs.

Quick Reference Card

CommandPurposeExample Use Case
comp file1 file2Compare two filesQuick verification
comp file1 file2 /dCompare with decimal outputHuman-readable differences
comp file1 file2 /aCompare with ASCII displayText file comparison
comp file1 file2 /a /lCompare with line numbersSource code comparison
comp file1 file2 /cCase-insensitive compareText files, ignore case
comp file1 file2 /n=100Compare first N linesLarge file header check
comp *.txt backup\*.txtCompare multiple filesBatch backup verification
comp file1 file2 > log.txtSave comparison resultsDocumentation/auditing

Try the Comp Command in Our Simulator

Practice the comp command safely in our Windows Command Simulator. No installation required—run comp, comp file1.txt file2.txt, and other examples in your browser. Perfect for learning, testing commands before running them on production systems, or demonstrating file comparison functionality in training environments.

Visit the Commands Reference for a full list of supported Windows CMD commands, including file management, comparison utilities, and system administration tools.

Summary

The comp command is essential for byte-by-byte file comparison in Windows Command Prompt. Use comp file1 file2 to verify files are identical, add /d for decimal difference display, or /a for ASCII character output. Comp stops after 10 mismatches by default, making it ideal for quick verification rather than detailed difference analysis.

Comp excels at binary file comparison—executables, databases, images, archives—where byte-level precision is critical. For text files where you want to see actual content that changed, use the related fc (File Compare) command instead. Both tools serve different purposes in file validation and quality assurance workflows.

Master comp for data integrity verification tasks like validating file transfers, confirming backup accuracy, detecting file corruption, verifying software builds, and quality assurance testing. The command's byte-level comparison and errorlevel reporting make it indispensable for automation scripts, batch validation, and ensuring file integrity across systems.

For large files where byte-by-byte comparison is slow, consider hash-based verification using certutil -hashfile to compute and compare SHA256 hashes—if hashes match, files are cryptographically certain to be identical. Combine comp's precision with hash verification's speed for comprehensive file integrity management.