What Is 7-Zip?
7-Zip is a free and open-source file archiver created by Igor Pavlov in 1999 and released under the GNU LGPL. It introduces the 7z container format, which supports very high compression ratios using the LZMA (Lempel-Ziv-Markov chain algorithm) and LZMA2 compression algorithms. 7-Zip became famous for consistently achieving 30–70% better compression than ZIP on typical software distributions.
7-Zip is cross-platform: the full GUI runs on Windows, while the command-line tool 7z (via p7zip) is available on Linux and macOS. The 7z format is specified in an open technical document, enabling independent implementations in many languages.
The 7z Format Architecture
Unlike ZIP's per-file compression, 7z uses solid compression by default — all files are concatenated and compressed as a single stream. This means:
- Dramatically better compression for many small similar files (e.g., source code, log files) because the compressor can find redundancy across files.
- No random access: to extract file N, you must decompress from the beginning of the solid block.
- Decompressor memory: LZMA2 with large dictionary sizes (up to 4 GB) requires significant RAM on both the compressor and decompressor.
The 7z container stores:
- Archive header (signature:
37 7A BC AF 27 1C) - Packed streams (compressed data blocks)
- Header with file metadata (names, sizes, timestamps, checksums, permissions)
The header itself is compressed and at the end of the file (similar to ZIP's central directory), enabling streaming append.
Compression Methods in 7z
| Method | Notes |
|---|---|
| LZMA | Default before 7-Zip 9.30 — dictionary up to 1.5 GB |
| LZMA2 | Default since 7-Zip 9.30 — multi-threaded, dictionary up to 4 GB |
| PPMD | Statistical compression — excellent for text, competes with LZMA on English text |
| BZip2 | Standard bzip2 — slower than LZMA, worse ratio |
| Deflate | zlib DEFLATE — for compatibility |
| Copy | Stored mode |
| Delta | Pre-processing filter for binary data (executable, audio, video) |
| BCJ / BCJ2 | x86 branch conversion filter — improves compression of x86 executables by 5–15% |
The most powerful configuration for software: LZMA2 + BCJ2 filter — used by major software distributors.
7z vs. ZIP: Compression Comparison
Typical results on a 100 MB software distribution (mix of executables, libraries, data):
| Format | Size | Compression time | Decompression time |
|---|---|---|---|
| Uncompressed | 100 MB | — | — |
| ZIP (Deflate, level 6) | 68 MB | 3 s | 1 s |
| ZIP (Deflate, level 9) | 65 MB | 12 s | 1 s |
| 7z (LZMA2, level 5) | 52 MB | 8 s | 3 s |
| 7z (LZMA2, level 9) | 48 MB | 35 s | 3 s |
| 7z (LZMA2, level 9 + BCJ2) | 42 MB | 40 s | 3 s |
7z consistently achieves 20–35% smaller archives than ZIP on software. Decompression is fast even at high compression levels because LZMA2 decompression is significantly simpler than compression.
AES-256 Encryption in 7z
7z supports AES-256 encryption with a key derived from the password via SHA-256 with 524,288 iterations (making brute-force attacks expensive). Crucially, 7z encrypts filenames and directory structure too — the archive appears as a single opaque blob. This is a significant security advantage over ZIP's AES encryption.
# Encrypt with AES-256 (includes filename encryption)
7z a -mhe=on -p"strong-password" encrypted.7z files/
# -mhe=on = header encryption (encrypts filenames too)
7-Zip Command-Line Reference
# Add files to archive (create)
7z a archive.7z files/
7z a -t7z -mx=9 archive.7z files/ # max compression
# Extract
7z x archive.7z # extract with full paths
7z e archive.7z # extract to current dir (no paths)
7z x archive.7z -o/output/dir/
# List contents
7z l archive.7z
# Test integrity
7z t archive.7z
# Update (add/replace)
7z u archive.7z newfile.txt
# Delete file from archive
7z d archive.7z unwanted.txt
# Create split archive (100 MB volumes)
7z a -v100m archive.7z largefile.iso
Supported Formats (Reading)
7-Zip can open and extract from many formats beyond 7z:
| Format | Read | Write |
|---|---|---|
| 7z | ✅ | ✅ |
| ZIP | ✅ | ✅ |
| GZIP | ✅ | ✅ |
| BZIP2 | ✅ | ✅ |
| XZ | ✅ | ✅ |
| TAR | ✅ | ✅ |
| RAR (v1-5) | ✅ | ❌ |
| ISO 9660 | ✅ | ❌ |
| WIM | ✅ | ✅ |
| DMG | ✅ | ❌ |
| CAB | ✅ | ❌ |
| MSI | ✅ | ❌ |
| NSIS installer | ✅ | ❌ |
| EXE (self-extracting) | ✅ | ✅ (7z SFX) |
| RPM / DEB | ✅ | ❌ |
| VHD / VMDK | ✅ | ❌ |
This makes 7-Zip a universal archive inspector tool even when 7z is not the distribution format.
Self-Extracting Archives (SFX)
7-Zip can create self-extracting .exe files — archives that decompress themselves without requiring 7-Zip to be installed on the target machine. Useful for distributing software to end users:
# Create SFX (Windows executable)
7z a -sfx archive.exe files/
# Custom SFX with GUI configuration
7z a -sfx7z.sfx -m0=LZMA2 -mx=9 setup.exe files/
LZMA Algorithm Deep Dive
LZMA (Lempel-Ziv-Markov chain Algorithm) combines:
- LZ77 dictionary matching — finds repeated strings in previous output and replaces them with (offset, length) pairs. Dictionary size determines how far back it looks (7-zip default: 16 MB; maximum: 4 GB).
- Markov chain range coder — arithmetic-like coder that encodes probabilities of symbols using context models. Much more efficient than Huffman coding for non-uniform distributions.
- Literal/match model — separate probability models for whether the next symbol is a literal byte or a match reference.
LZMA2 adds:
- Multi-threading: splits input into chunks processed by independent LZMA streams.
- Incompressible block pass-through: chunks that cannot be compressed are stored uncompressed without penalty.
- Simpler container: no framing complications of LZMA (fixes the partial-flush issue).
7z in Software Ecosystems
- Inno Setup: Windows installer framework — can use 7z LZMA2 compression internally.
- NSIS: Nullsoft Scriptable Install System — alternative installer using 7z.
- pacman (Arch Linux): uses
.pkg.tar.zst(Zstandard) but historically used.pkg.tar.xzwhich is LZMA2. - RPM / DEB: can contain LZMA2/XZ payloads since LZMA adoption.
- Wine: includes 7z for extracting Windows installers.
7z vs. RAR
| Feature | 7z | RAR |
|---|---|---|
| License | Free, open source | Proprietary (free to decompress) |
| Compression | LZMA2 | RAR5 (128 MB dictionary) |
| Ratio | ~Equal | Slightly worse than 7z |
| Encryption | AES-256 + filename encryption | AES-256 + filename encryption |
| Recovery records | No | Yes (parity data for corrupt archives) |
| Solid archives | Yes | Yes |
| Split archives | Yes | Yes |
| Reading on Linux | p7zip (7z) | unrar (free) |
| Cost | Free | ~$40 for WinRAR (though never enforced) |
Choose 7z for open-source workflows. Choose RAR only if recovery records (repair capability) are critical.
Best Practices
- Use LZMA2 compression level 5 for a good speed/ratio balance; level 9 for distribution archives where compression time is acceptable.
- Enable solid mode (default) for many small similar files; disable for large heterogeneous files where random access is needed.
- Use
-mhe=onto encrypt headers (filenames) along with content for sensitive archives. - Use strong passwords — 7z's AES-256 with 500K SHA-256 iterations is resistant to brute force only if the password is high-entropy.
- Specify dictionary size (
-md=256m) based on available RAM — larger dictionaries improve ratio but require RAM during decompression. - Use BCJ filter (
-mf=BCJ2) when compressing executables and DLLs. - Create split volumes for archives that must be transmitted via size-limited channels.
- Test archives after creation with
7z t. - Prefer 7z over RAR for open-source and cross-platform scenarios.
- Use XZ (LZMA2) via TAR on Linux for package distribution — it is a streaming format without the 7z container overhead.
Related conversions
Archive format conversions used most often: