Skip to main content
Technology & EngineeringFile Formats166 lines

7-Zip Compressed Archive

The 7z archive format — open-source high-ratio compression using LZMA2, with strong AES-256 encryption, solid archives, and multi-threading support.

Quick Summary28 lines
You are a file format specialist with deep expertise in the 7z archive format. You understand its LZMA/LZMA2 compression algorithms, solid archive mode, AES-256 encryption, BCJ filter chains for executables, and the internal block structure. You can advise on optimal compression settings, parallel compression with multi-threading, volume splitting, encryption best practices, and choosing between 7z and alternative archive formats.

## Key Points

- **Extension:** `.7z`
- **MIME type:** `application/x-7z-compressed`
- **Magic bytes:** `7z\xBC\xAF\x27\x1C` (6 bytes)
- **Max file size:** 16 EB (theoretical)
- **Compression methods:** LZMA, LZMA2 (default), PPMd, BZip2, DEFLATE, Delta, BCJ/BCJ2 (executable filters)
- **Encryption:** AES-256 in CBC mode with SHA-256 key derivation (configurable iterations)
- **License:** LGPL (format and reference implementation)
- Metadata (file listing) is stored at the end and can itself be compressed/encrypted
- Solid blocks group multiple files into a single compression stream
- Filter chains allow preprocessing (e.g., BCJ filter for executables before LZMA2)
- **Software distribution:** Open-source project releases, SDK packages
- **Source code archiving:** Solid compression on similar text files yields excellent ratios

## Quick Example

```
[Signature Header (32 bytes)]
[Packed Streams (compressed file data)]
...
[Encoded Headers (compressed metadata)]
[End Header (points to metadata location)]
```
skilldb get file-formats-skills/7-Zip Compressed ArchiveFull skill: 166 lines
Paste into your CLAUDE.md or agent config

You are a file format specialist with deep expertise in the 7z archive format. You understand its LZMA/LZMA2 compression algorithms, solid archive mode, AES-256 encryption, BCJ filter chains for executables, and the internal block structure. You can advise on optimal compression settings, parallel compression with multi-threading, volume splitting, encryption best practices, and choosing between 7z and alternative archive formats.

7-Zip Compressed Archive (.7z)

Overview

7z is an open-source archive format introduced with the 7-Zip archiver by Igor Pavlov in 1999. It achieves some of the highest compression ratios among general-purpose archivers, primarily through the LZMA and LZMA2 algorithms. The format is fully open, patent-free, and supported by an extensive ecosystem of tools.

7z excels at compressing text, source code, binaries, and collections of similar files through solid compression mode.

Core Philosophy

7z prioritizes compression ratio above all else. Using the LZMA/LZMA2 algorithm, 7z consistently produces smaller archives than ZIP, gzip, or bzip2 — often 30-70% smaller depending on content. This makes 7z the optimal choice when minimizing file size matters more than compression speed, decompression speed, or universal compatibility.

The tradeoff for superior compression is slower encoding and broader but not universal tool support. ZIP is natively supported by every operating system; 7z requires 7-Zip, p7zip, or a compatible archiver. For distributing files to technical users who can install the right tool, 7z's size advantage is worth the friction. For distributing to general audiences, ZIP's universal support is more important than 7z's better compression.

7z also supports AES-256 encryption, solid archive mode (compressing multiple files as a single stream for better ratios), and self-extracting archives. Use solid mode for archives of many similar files (source code, documents) where cross-file redundancy boosts compression. Avoid solid mode for archives where individual file extraction speed matters, since solid archives must decompress from the beginning to reach any file.

Technical Specifications

  • Extension: .7z
  • MIME type: application/x-7z-compressed
  • Magic bytes: 7z\xBC\xAF\x27\x1C (6 bytes)
  • Max file size: 16 EB (theoretical)
  • Compression methods: LZMA, LZMA2 (default), PPMd, BZip2, DEFLATE, Delta, BCJ/BCJ2 (executable filters)
  • Encryption: AES-256 in CBC mode with SHA-256 key derivation (configurable iterations)
  • License: LGPL (format and reference implementation)

Internal Structure

[Signature Header (32 bytes)]
[Packed Streams (compressed file data)]
...
[Encoded Headers (compressed metadata)]
[End Header (points to metadata location)]

Key design decisions:

  • Metadata (file listing) is stored at the end and can itself be compressed/encrypted
  • Solid blocks group multiple files into a single compression stream
  • Filter chains allow preprocessing (e.g., BCJ filter for executables before LZMA2)

How to Work With It

Creating 7z Archives

# Basic creation
7z a archive.7z folder/

# Maximum compression with LZMA2
7z a -t7z -m0=lzma2 -mx=9 -ms=on archive.7z files/

# Encrypt with AES-256 (encrypts filenames too with -mhe=on)
7z a -p"password" -mhe=on archive.7z secret/

# Multi-threaded compression
7z a -mmt=on archive.7z largefolder/

# Split into volumes
7z a -v100m archive.7z largefile.iso

# Exclude patterns
7z a archive.7z folder/ -xr!*.log -xr!node_modules

Extracting

7z x archive.7z                    # extract with full paths
7z e archive.7z -o/target/dir/     # extract flat (no directory structure)
7z l archive.7z                    # list contents
7z t archive.7z                    # test integrity

# Python (py7zr library)
import py7zr
with py7zr.SevenZipFile('archive.7z', 'r') as z:
    z.extractall('/target/dir')

Optimizing Compression

# For text/source code (PPMd often beats LZMA2)
7z a -m0=ppmd -mx=9 code.7z src/

# For executables (BCJ2 filter + LZMA2)
7z a -m0=BCJ2 -m1=LZMA2:d=1g program.7z *.exe *.dll

# For mixed content, let 7-Zip auto-detect
7z a -mx=9 -ms=on mixed.7z folder/

# Ultra compression (slow, high memory)
7z a -t7z -m0=lzma2:d=1536m -mx=9 -ms=on -mmt=2 ultra.7z data/

Common Use Cases

  • Software distribution: Open-source project releases, SDK packages
  • Source code archiving: Solid compression on similar text files yields excellent ratios
  • Backup compression: High ratio for infrequent access archives
  • Executable distribution: BCJ filters optimize binary compression
  • Large dataset compression: Scientific data, database dumps
  • Cross-platform archiving: Open format works everywhere

Pros & Cons

Pros

  • Among the highest compression ratios for general-purpose archiving
  • Completely open-source and patent-free (LGPL license)
  • Strong AES-256 encryption with optional filename encryption
  • Solid compression dramatically improves ratio for similar files
  • Pluggable compression methods and filter chains
  • Multi-threaded LZMA2 compression scales well on modern CPUs
  • Self-extracting archive support

Cons

  • Slower compression and decompression than ZIP or Zstandard
  • No native OS support — requires third-party software to open
  • No error recovery records (unlike RAR)
  • Solid archives must decompress sequentially (no random access to individual files)
  • High memory usage at maximum compression settings (can require several GB)
  • Less universal than ZIP for sharing with non-technical users

Compatibility

PlatformSupportPrimary Tools
Windows7-Zip, PeaZip, WinRAR7-Zip is the reference implementation
macOSKeka, The Unarchiver, p7zipNo native support
Linuxp7zip, 7z CLIAvailable in all distros via package manager
AndroidZArchiver, RARGood third-party support
iOSiZip, DocumentsLimited support

Programming languages: Python (py7zr), Node.js (node-7z, wraps CLI), Java (Apache Commons Compress), C/C++ (7z SDK), Rust (sevenz-rust), Go (go7z).

Related Formats

  • ZIP — More universal but lower compression ratio
  • RAR — Comparable compression, proprietary, has recovery records
  • XZ/LZMA — Same LZMA algorithm for single-stream compression (used in tar.xz)
  • Zstandard — Much faster compression/decompression, slightly lower ratio
  • TAR.7z — Uncommon but possible; tar.xz is preferred on Unix

Practical Usage

  • Source code release packaging: Use 7z a -t7z -m0=lzma2 -mx=9 -ms=on release.7z src/ with solid compression to get 30-50% smaller archives than ZIP for source code distributions.
  • Encrypted backup of sensitive files: Use 7z a -p -mhe=on backup.7z confidential/ to encrypt both file contents and filenames, making it impossible to see what is inside without the password.
  • Distributing large binary packages: Apply BCJ2 filters for executables (7z a -m0=BCJ2 -m1=LZMA2 dist.7z *.exe *.dll) to significantly improve compression of compiled binaries.
  • Splitting for upload limits: Use volume splitting (7z a -v50m archive.7z largefile.iso) when sharing files through services with per-file size limits.
  • Comparing compression methods: Test PPMd for text-heavy content (7z a -m0=ppmd -mx=9) versus LZMA2 for mixed content to find the best ratio for your specific data.

Anti-Patterns

  • Using 7z for archives that need random access to individual files — Solid compression means extracting a single file requires decompressing all preceding files in the block. Use ZIP or non-solid mode if individual file extraction is a common operation.
  • Setting maximum dictionary size on memory-constrained systems — Ultra compression with -m0=lzma2:d=1536m requires several GB of RAM for both compression and decompression. Recipients may not have enough memory to extract the archive.
  • Choosing 7z over ZIP for sharing with non-technical users — ZIP is natively supported on all operating systems without additional software. Use 7z only when the recipient is known to have 7-Zip or an equivalent tool.
  • Relying on 7z for long-term archival without redundancy — 7z has no error recovery records. A single corrupted byte can make a solid block unrecoverable. Pair with PAR2 parity files or use RAR with recovery records for critical archives.
  • Using encryption without filename encryption — Without -mhe=on, the archive structure and filenames are visible even though contents are encrypted, leaking metadata about what is stored inside.

Install this skill directly: skilldb add file-formats-skills

Get CLI access →