CMD Simulator
File Systemcompact

COMPACT Command Guide - Display and Manage File Compression in Windows

Learn how to use the compact command to display, enable, or disable NTFS file and directory compression in Windows Command Prompt. Includes syntax, examples, and compression best practices.

Rojan Acharya·
Share

The compact command is a Windows Command Prompt utility that displays, enables, or disables NTFS file system compression for files and directories. Use /c to compress and /u to uncompress files; combine with /s for recursive operations across entire directory trees. NTFS compression is transparent to applications—compressed files work normally while saving disk space.

Whether you're managing limited storage on older systems, archiving infrequently accessed data, or optimizing disk usage on enterprise servers, mastering compact gives you built-in compression capabilities without third-party tools. System administrators rely on this command for automated storage optimization, particularly on file servers with large document repositories and archival storage.

This comprehensive guide covers compact syntax, all compression options, practical examples for common scenarios, compression ratios for different file types, troubleshooting tips, related commands, and frequently asked questions. By the end, you'll confidently manage NTFS compression from the command line for storage optimization and system administration tasks.

What Is the Compact Command?

The compact command has been part of Windows since Windows NT 3.1, making it one of the most mature NTFS features available. It provides access to NTFS's built-in compression algorithm, which operates at the file system level and is completely transparent to applications and users.

NTFS compression differs from archive formats like ZIP or RAR in several important ways:

  • Transparent access – Compressed files open normally in applications without manual extraction
  • Automatic compression – New files inherit compression state from parent directory
  • Real-time operation – Compression and decompression happen automatically as files are accessed
  • No additional software – Built into NTFS; works on all modern Windows versions
  • Block-level compression – Only modified blocks are recompressed, not entire files

The command works in Command Prompt (CMD), Windows PowerShell (with CMD compatibility), and is available in Windows 11, Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, and all Windows Server editions. NTFS compression requires NTFS file system—it doesn't work on FAT32 or exFAT volumes.

System administrators use compact in login scripts, scheduled tasks, and storage optimization procedures. Common use cases include compressing user profile directories, log file archives, documentation repositories, and infrequently accessed project files. The command provides granular control over compression that Windows Explorer's interface can't match, particularly for bulk operations and scripting.

Compact Command Syntax

The basic syntax for the compact command is:

compact [/c | /u] [/s[:dir]] [/a] [/i] [/f] [/q] [pathname [...]]

Parameters and Switches

ParameterDescription
/cCompress the specified files or directories
/uUncompress (decompress) the specified files or directories
/s[:dir]Perform operation recursively on all subdirectories. Optionally specify starting directory
/aDisplay files with hidden or system attributes (normally skipped)
/iContinue operation even if errors occur (ignore errors)
/fForce compression on all files, even those already compressed
/qQuiet mode—report only essential information
pathnameSpecifies the file(s) or directory pattern to process

If you run compact without parameters, it displays the compression state of the current directory and files within it. This is useful for quick audits before making compression changes.

Important Notes on Switches

  • /c and /u are mutually exclusive – You can compress or uncompress in a single command, not both
  • /s operates recursively – Use with caution on large directory trees (can take time)
  • /a reveals hidden files – Essential for system directories and hidden archives
  • /i prevents operation termination – Useful for bulk operations where some files may be locked
  • /f recompresses files – Helpful after upgrading Windows or applying compression updates

Understanding NTFS Compression

How NTFS Compression Works

NTFS compression uses the LZNT1 algorithm (LZ77 variant) to compress data in 16-cluster compression units. When a file is marked for compression:

  1. Windows compresses data as it's written to disk
  2. Compressed data is stored in compression units (typically 64 KB)
  3. File system tracks compressed and uncompressed sizes
  4. Decompression happens transparently when files are read
  5. Modified blocks are recompressed automatically on write

Compression Ratios by File Type

Compression effectiveness varies dramatically by file type:

File TypeTypical Compression RatioNotes
Text files (.txt, .log, .csv)60-80%Excellent compression
Office documents (.docx, .xlsx)40-60%Good compression (already compressed internally)
Source code (.js, .ts, .py, .java)60-75%Very good compression
HTML/XML/JSON65-80%Excellent compression due to repetitive structure
Database files (.mdb, .db)30-70%Varies by content and database type
Executables (.exe, .dll)40-60%Moderate compression
Images (.jpg, .png, .gif)0-5%Already compressed; may increase size
Videos (.mp4, .avi, .mkv)0-2%Already compressed; no benefit
Archives (.zip, .rar, .7z)0-1%Already compressed; avoid NTFS compression

Pro tip: Only compress text-based files, uncompressed images (BMP, TIF), and documents. Avoid compressing already-compressed formats—it wastes CPU cycles and may actually increase file sizes due to compression overhead.

Performance Considerations

NTFS compression has CPU overhead and performance implications:

  • CPU usage increases – Compression/decompression is CPU-intensive
  • Read performance – Slightly slower due to decompression (5-15% overhead)
  • Write performance – Noticeably slower due to compression (15-30% overhead)
  • SSD considerations – Less beneficial on SSDs (fast storage, compression adds overhead)
  • HDD optimization – More beneficial on HDDs (slower storage, less data to read = faster)
  • Server environments – Acceptable for archival storage; avoid for high-traffic databases

Best practice: Use NTFS compression on infrequently accessed data (archives, old logs, documentation) where disk space savings outweigh CPU overhead. Avoid on performance-critical directories (databases, application binaries, VM files).

Compressing Files and Directories

Compress a Single File

To compress a specific file:

compact /c C:\Documents\report.txt

Output:

Compressing files in C:\Documents\

report.txt           [Compressing]

1 file within 1 directory was compressed.
200,000 total bytes of data are stored in 80,000 bytes.
The compression ratio is 2.5 to 1.

The compression ratio shows how much space was saved. A ratio of 2.5:1 means the file occupies 40% of its original size (60% savings).

Compress All Files in a Directory

To compress all files in the current directory (non-recursive):

compact /c *

This compresses only files directly in the current directory, not subdirectories. Use /s for recursive operation.

Compress Directory and All Subdirectories

To compress a directory and everything beneath it recursively:

compact /c /s C:\Archives

This command:

  1. Compresses all files in C:\Archives
  2. Compresses all subdirectories recursively
  3. Sets compression attribute on directories (new files inherit compression)
  4. Reports compression statistics for each directory

Enterprise use case: Compress user profile archives, completed project directories, and historical log files to reclaim disk space on file servers.

Compress with Hidden and System Files

By default, compact skips hidden and system files. To include them:

compact /c /a /s C:\Logs

The /a switch ensures hidden log files, system files, and files with special attributes are also compressed. Essential for system directories and complete compression coverage.

Force Recompression

If files are already compressed but you want to recompress (after compression algorithm updates or to fix corruption):

compact /c /f /s C:\Data

The /f switch forces recompression even if files are already marked as compressed. Useful after Windows updates that improve compression algorithms.

Decompressing Files and Directories

Uncompress a Single File

To remove compression from a specific file:

compact /u C:\Documents\report.txt

The file expands to its original, uncompressed size. Use this when you need maximum performance for frequently accessed files.

Uncompress All Files in a Directory

To uncompress everything in the current directory:

compact /u *

This removes compression from files but doesn't affect subdirectories unless you add /s.

Uncompress Directory Recursively

To uncompress a directory tree:

compact /u /s C:\Database

This recursively decompresses all files and removes the compression attribute from directories. New files added to these directories will not be compressed.

Performance optimization: Uncompress database directories, virtual machine files, and application directories where I/O performance is critical.

Uncompress in Quiet Mode

For large operations where you want minimal output:

compact /u /s /q C:\Projects\Archived

Quiet mode (/q) suppresses detailed progress, showing only essential information and final statistics. Ideal for scheduled tasks and batch scripts.

Displaying Compression Status

Check Current Directory

To see compression status of the current directory:

compact

Output:

Listing C:\Data\
New files added to this directory will be compressed.

     80000 :   200000 = 2.5 to 1 [C] report.txt
    120000 :   400000 = 3.3 to 1 [C] data.log
           :           [UC] image.jpg
           :           [UC] video.mp4

Of 4 files within 1 directory
2 are compressed and 2 are not compressed.
320,000 total bytes of data are stored in 200,000 bytes.
The compression ratio is 1.6 to 1.

Legend:

  • [C] – File is compressed
  • [UC] – File is uncompressed
  • First number – Compressed size on disk
  • Second number – Original uncompressed size

Check Specific Directory

To check compression status of a specific directory:

compact C:\Logs

This displays compression state for all files in C:\Logs without modifying anything.

Check Recursively

To audit compression across a directory tree:

compact /s C:\Archives

This reports compression status for every subdirectory, showing total space savings across the entire tree. Useful for storage audits and capacity planning.

Common Use Cases

Archive Old Project Files

Compress completed projects to free disk space while maintaining accessibility:

compact /c /s "C:\Projects\2023\Completed"

Files remain accessible to users and applications but occupy 40-70% less disk space. Ideal for archival storage on file servers.

Optimize Log File Storage

Compress log directories where text files compress exceptionally well (70-80%):

compact /c /s /a C:\Logs

Include /a to compress hidden logs. Old logs rarely accessed but must be retained—perfect candidates for NTFS compression.

Compress User Profile Archives

On file servers, compress inactive user profiles:

compact /c /s "C:\Users\OldProfiles\jsmith"

User profiles contain documents, settings, and cached data that compress well. Reclaim storage on servers with many archived profiles.

Uncompress Performance-Critical Directories

Remove compression from frequently accessed directories:

compact /u /s C:\WebServer\www

Web server document roots, database directories, and application folders should not be compressed—performance is more important than space savings.

Compress Document Repositories

Compress shared document libraries and knowledge bases:

compact /c /s "\\FileServer\Shared\Documentation"

Office documents, PDFs, and text files compress well and are infrequently modified. Network share paths work with compact.

Selective Compression by File Type

Compress only text-based files in a directory:

compact /c /s C:\Data\*.txt
compact /c /s C:\Data\*.log
compact /c /s C:\Data\*.csv

Target specific file types that compress well while leaving others uncompressed. Requires separate commands for each extension.

Space Recovery on Low-Disk Systems

Emergency disk space recovery on systems running low:

compact /c /s C:\Users\%USERNAME%\Documents
compact /c /s C:\ProgramData\Logs

Compress user documents and application logs to immediately free 30-50% of space in these directories.

Batch Compression Script

Create a batch script for scheduled compression:

@echo off
echo Compressing archive directories...
compact /c /s /q C:\Archives
compact /c /s /q C:\Logs\Old
compact /c /s /q "C:\Users\OldProfiles"
echo Compression complete.

Schedule via Task Scheduler for automated maintenance. Use /q for quiet operation in scheduled tasks.

Tips and Best Practices

Choose Compression Candidates Wisely

Compress text-based files (documents, source code, logs, CSV files) where you'll see 60-80% space savings. Avoid compressing already-compressed formats (JPEG, MP4, ZIP, RAR)—you'll waste CPU with no benefit or even increase file sizes.

Monitor CPU Impact

NTFS compression adds CPU overhead. On older systems or CPU-constrained servers, excessive compression can degrade performance. Monitor CPU usage after enabling compression on high-traffic directories.

Use Compression for Cold Storage

Apply compression to infrequently accessed data (archives, old projects, historical logs). For hot data (databases, web servers, VMs), compression overhead outweighs space savings.

Test Before Enterprise Deployment

Run compression on test directories first. Measure space savings, compression time, and impact on application performance before rolling out to production file servers.

Combine with Quota Management

In enterprise environments, use NTFS compression alongside disk quotas. Compressed files count toward quotas at their uncompressed size, giving users more effective storage capacity.

Document Compression Policies

Create organizational policies for which directories should be compressed. Document exceptions (performance-critical paths, database directories, VM storage) to prevent accidental compression.

Avoid Compression on SSDs for Performance Workloads

On SSDs, disk space is rarely the bottleneck—performance is. NTFS compression adds CPU overhead without the HDD benefit of reading less data. Reserve SSD compression for archival volumes only.

Use Quiet Mode in Scripts

Always include /q in batch files and scheduled tasks. Verbose output can cause scripts to pause or generate unnecessary logs.

Check Compatibility with Encrypted Files

NTFS compression and EFS (Encrypted File System) are mutually exclusive on the same file. You can't compress encrypted files. Choose compression or encryption based on priority (security vs. space).

Regular Compression Audits

Schedule monthly audits with compact /s to verify compression ratios. If ratios degrade (files changing to already-compressed formats), adjust compression policies.

Exclude Backup Targets

Don't compress directories used as backup destinations. Backup software often compresses data—double compression wastes CPU. Additionally, some backup tools perform better with uncompressed source files.

Set Folder Compression for Inheritance

When compressing directories with /c /s, the directory itself gets the compression attribute. New files created in these directories automatically inherit compression—no need to run compact again.

Troubleshooting Common Issues

"Access Denied" Error

Problem: compact /c fails with "Access denied" for system files or protected directories.

Cause: Insufficient permissions or files locked by running applications.

Solution:

  1. Run Command Prompt as Administrator (right-click → "Run as administrator")
  2. Use /i to ignore errors and continue with remaining files
  3. Close applications that may have files open
  4. For system files, ensure you have NTFS permissions (use takeown or icacls if needed)

Prevention: Always run compact with administrator privileges when working with system directories.

Compression Has No Effect

Problem: Running compact /c reports success but file sizes don't change.

Cause: Files are already compressed formats (JPG, MP4, ZIP) that don't benefit from NTFS compression.

Solution:

  1. Check file types—avoid compressing already-compressed formats
  2. Run compact to verify compression state (files show [C] marker)
  3. Check actual disk space with dir /c (shows compressed sizes)
  4. Some files compress minimally—ratios of 1.1:1 are possible for incompressible data

Prevention: Target text-based files and uncompressed formats only.

Performance Degradation After Compression

Problem: Applications or file access becomes noticeably slower after enabling compression.

Cause: CPU overhead from real-time decompression exceeds benefits of reduced disk I/O.

Solution:

  1. Identify directories with high access frequency
  2. Uncompress performance-critical paths: compact /u /s C:\DatabaseFiles
  3. Monitor CPU usage—if consistently high, reduce compression scope
  4. Reserve compression for infrequently accessed archives

Prevention: Never compress database files, virtual machines, or high-traffic web server directories.

"The System Cannot Find the File Specified"

Problem: compact fails to find specified files or directories.

Cause: Incorrect path syntax, missing directories, or permission issues.

Solution:

  1. Verify path exists: dir C:\Path\To\Directory
  2. Use quotes for paths with spaces: compact /c "C:\My Documents"
  3. Check spelling and drive letters
  4. Ensure you have read permissions on the directory

Prevention: Always use dir to verify paths before running bulk compact operations.

Compression Removes Encryption

Problem: Files lose EFS encryption after running compact.

Cause: NTFS compression and EFS encryption are mutually exclusive—can't have both simultaneously.

Solution:

  1. Choose between compression and encryption based on priority
  2. For sensitive data, use encryption (security > space savings)
  3. For non-sensitive archives, use compression (space > security)
  4. Re-encrypt files if accidentally decompressed: cipher /e

Prevention: Document which directories require encryption vs. compression in your security policy.

Slow Recursive Compression

Problem: compact /c /s on large directories takes extremely long.

Cause: Processing millions of files or very large individual files.

Solution:

  1. Use /q for quiet mode to reduce output overhead
  2. Break operation into smaller directory chunks
  3. Run during off-hours to avoid performance impact
  4. Consider using PowerShell with parallel processing for massive operations
  5. Monitor with Task Manager—if I/O-bound, operation is progressing

Prevention: Test on subdirectories first; estimate time based on file counts and sizes.

Related Commands

diskpart – Advanced Disk Management

While compact handles file-level compression, diskpart manages volumes, partitions, and disk properties. Use diskpart for volume creation and management; use compact for compression on existing NTFS volumes.

fsutil – File System Utility

fsutil provides low-level file system operations including sparse file management and compression statistics. Use fsutil behavior query disablecompression to check if compression is disabled system-wide.

cipher – Encryption Management

cipher manages EFS (Encrypting File System) operations. Since NTFS compression and EFS encryption are mutually exclusive, choose cipher for security-focused scenarios and compact for space-focused scenarios.

attrib – File Attributes

attrib manages file attributes (read-only, hidden, system, archive) while compact manages compression state. Both are complementary file management tools—use attrib for access control and compact for storage optimization.

icacls – Advanced Permissions

icacls manages NTFS permissions. Before running compact on secured directories, use icacls to verify you have necessary permissions (modify or full control) to change file properties.

chkdsk – File System Repair

chkdsk verifies and repairs NTFS volumes. If compression causes issues or produces errors, run chkdsk /f to repair file system structures before retrying compact operations.

Frequently Asked Questions

What does compact /c do?

compact /c enables NTFS compression on specified files or directories. The /c switch stands for "compress" and applies NTFS's built-in compression algorithm to reduce disk space usage. Compressed files remain fully accessible to all applications without manual extraction—compression and decompression happen transparently at the file system level.

How much space does NTFS compression save?

Space savings vary by file type. Text files, logs, and documents typically compress 60-80% (saving 40-80% disk space). Office documents compress 40-60%. Already-compressed formats (JPG, MP4, ZIP) see 0-5% savings. Actual ratios depend on file content—repetitive data compresses better than random data.

Does compact slow down file access?

Yes, NTFS compression adds CPU overhead. Read operations are 5-15% slower due to decompression; writes are 15-30% slower due to compression. Impact is minimal for infrequently accessed files (archives, old logs) but noticeable for high-traffic directories (databases, web servers). Use compression only for cold storage.

Can I use compact on external drives?

Yes, but only if the external drive is formatted as NTFS. Compact doesn't work on FAT32, exFAT, or non-Windows file systems. Format external drives as NTFS to use compression. USB drives and external HDDs formatted as NTFS support compact operations.

What's the difference between compact and ZIP compression?

Compact uses NTFS-level compression that's transparent to applications—files work normally without extraction. ZIP creates archive files that must be manually extracted before use. Compact is better for working files you need immediate access to; ZIP is better for transfer, backup, or long-term archival where extraction is acceptable.

How do I uncompress files compressed with compact?

Use compact /u to remove NTFS compression. For example: compact /u C:\Data\file.txt uncompresses a single file, or compact /u /s C:\Data uncompresses an entire directory tree. Files expand to original size and lose the compression attribute.

Does Windows automatically decompress compact files?

Yes, decompression is completely transparent. When applications read compressed files, Windows automatically decompresses data in memory. Users and applications don't need to do anything special—compressed files behave identically to uncompressed files, just with slightly higher CPU usage during access.

Can I compress system files with compact?

Yes, but exercise caution. Run Command Prompt as Administrator and use compact /c /a to include system files. However, compressing critical Windows system directories can impact boot time and system performance. Only compress system logs, old installer files, and non-critical system data.

Will compression corrupt my files?

No, NTFS compression is a stable, mature file system feature that doesn't corrupt data. Windows has used this compression algorithm since Windows NT 3.1 (1993). However, always maintain backups before large compression operations—not due to corruption risk, but as general best practice for bulk changes.

How do I check if a file is compressed?

Run compact in the directory containing the file. Compressed files show [C] marker and display compressed vs. uncompressed sizes. Alternatively, right-click the file in Windows Explorer, choose Properties → Advanced, and check "Compress contents to save disk space."

Can I compress individual files in an uncompressed directory?

Yes, compress individual files with compact /c filename. However, best practice is to set compression at the directory level—this ensures new files automatically inherit compression. Directory-level compression is more maintainable than managing compression on individual files.

Does compact work with SSD drives?

Technically yes—compact works on any NTFS volume including SSDs. However, compression on SSDs rarely makes sense. SSDs are fast but compression adds CPU overhead without the HDD benefit of reducing mechanical read time. Only compress on SSDs if disk space is critically limited and performance is not a concern.

Quick Reference Card

CommandPurposeExample
compactDisplay compression statusCheck current directory
compact /c file.txtCompress single fileSave disk space on one file
compact /c /s C:\DataCompress directory recursivelyCompress entire directory tree
compact /u file.txtUncompress single fileRestore to uncompressed state
compact /u /s C:\DataUncompress directory recursivelyRemove compression from tree
compact /c /a /s C:\LogsCompress including hidden filesComplete compression coverage
compact /c /s /q C:\ArchivesCompress quietly (minimal output)Batch/script operations
compact /c /f /s C:\DataForce recompressionFix corruption or update algorithm

Try Compact in Our Simulator

Want to practice using the compact command without affecting your system? Try our interactive Windows Command Simulator to experiment with compression operations in a safe, simulated environment. Practice compression syntax, test recursive operations, and see simulated output before running commands on your actual system.

For more file system commands, browse our comprehensive Commands Reference with over 200 Windows commands, syntax guides, and practical examples.

Summary

The compact command provides powerful, built-in NTFS compression capabilities for optimizing disk space usage on Windows systems. By enabling transparent file system compression, you can reduce storage requirements by 40-80% for text-based files while maintaining full application compatibility and user access.

Key takeaways: Use /c to compress and /u to uncompress files and directories. Combine with /s for recursive operations across directory trees. Target text files, documents, logs, and source code—avoid compressing already-compressed formats like JPEG, MP4, and ZIP. Apply compression to cold storage and archives; avoid for performance-critical directories like databases and web servers.

NTFS compression adds CPU overhead (5-15% for reads, 15-30% for writes) but reduces disk I/O by storing less data. This tradeoff favors HDDs over SSDs and archival storage over active workloads. Use compact without parameters to audit compression status and calculate space savings before making changes.

For system administrators, compact is essential for storage optimization on file servers, user profile archival, log management, and capacity planning. Implement compression policies that balance space savings with performance requirements, and regularly audit compression ratios to ensure effectiveness.

Master the compact command to reclaim disk space, extend storage capacity, and optimize file server efficiency—all without third-party compression tools or user workflow disruption. NTFS compression is transparent, stable, and built into every modern Windows system.