All formats

7z (7-Zip archive)

Full name7z archive (7-Zip)
Extensions.7z, .7z.001, .7z.002... (multi-volume), .cb7 (comic book), .exe (self-extracting)
MIME typeapplication/x-7z-compressed
Typearchive, lossless compression, optional encryption
Starts with37 7A BC AF 27 1C (7z\xBC\xAF\x27\x1C)
Specification7zFormat.txt in the 7-Zip / LZMA SDK source
Maintained byIgor Pavlov (7-Zip)
Licenseopen; the format and the LZMA SDK are public domain, no patents

7z is the native archive format of 7-Zip. It packs many files and folders into one file and compresses them, by default with LZMA2. It usually produces smaller archives than ZIP, especially for many similar files, because it can compress files together in solid blocks. It supports AES-256 encryption of file data and of file names, Unicode names, files larger than 4 GB and archives split into volumes.

7z is used for software distribution, backups, game mods, large data sets and comic books (.cb7). Its main downside is support: ZIP opens everywhere without extra software, 7z needs 7-Zip or another archiver on most systems (Windows 11 now opens it natively).

When to use 7z#

File structure#

A 7z file has 3 parts: a fixed 32-byte signature header, the packed streams (compressed file data), and the header that describes everything, stored at the end of the file. The signature header points to the end header, so a reader seeks to the end first.

+---------------------------+  offset 0
| Signature header (32 B)   |  magic, version, offset/size/CRC of the end header
+---------------------------+  offset 32
| Packed stream 0           |  compressed data of folder (block) 0
| Packed stream 1           |
| ...                       |
+---------------------------+  32 + NextHeaderOffset
| Header                    |  file list, folders, coders, sizes, CRCs, names, times
| (often itself compressed) |
+---------------------------+  end of file

Signature header#

All integers in the signature header are little-endian.

Offset Size Field Description
0 6 Signature 37 7A BC AF 27 1C
6 2 Version major, minor: 00 04 in current files
8 4 StartHeaderCRC CRC-32 of the next 20 bytes
12 8 NextHeaderOffset offset of the header, counted from byte 32
20 8 NextHeaderSize size of the header in bytes
28 4 NextHeaderCRC CRC-32 of the header

A complete 139-byte archive made by 7-Zip with one file, hello.txt (13 bytes, “hello, world\n”):

37 7A BC AF 27 1C          signature
00 04                      version 0.4
F7 06 D1 70                StartHeaderCRC
11 00 00 00 00 00 00 00    NextHeaderOffset = 17
5A 00 00 00 00 00 00 00    NextHeaderSize = 90
19 49 C3 07                NextHeaderCRC
01 00 0C 68 65 6C 6C 6F    packed stream (17 bytes): an LZMA2 "stored" chunk
2C 20 77 6F 72 6C 64 0A    with the 13 bytes of hello.txt, then end marker 00
00
01                         header (90 bytes) starts: kHeader
04                           kMainStreamsInfo
06 00 01 09 11 00              kPackInfo: pack pos 0, 1 stream, size 17
07 0B 01 00 01 21 21 01 00     kUnpackInfo: 1 folder, 1 coder, id 21 = LZMA2, 1 property byte
0C 0D 00                       unpacked size 13
08 0A 01 53 74 24 F4 00 00     kSubStreamsInfo: CRC-32 of the file F4247453
05 01                        kFilesInfo: 1 file
19 0C 00 ... 00                kDummy (padding for alignment)
11 15 00 68 00 65 00 ...       kName: "hello.txt" in UTF-16LE, 0-terminated
14 0A 01 00 88 04 DB B9 ...    kMTime: Windows FILETIME
15 06 01 00 20 00 00 00        kWinAttributes: 0x20 = archive
00 00                        end of FilesInfo, end of Header

The header#

The header is a tree of properties. Each property starts with a 1-byte ID; numbers inside use a variable-length encoding (1 to 9 bytes, the count of leading 1-bits in the first byte gives the number of extra bytes). Main property IDs:

ID Name Contents
01 kHeader the plain header
17 kEncodedHeader the header is itself compressed (usually LZMA); this record says how to unpack it
04 kMainStreamsInfo PackInfo + UnpackInfo + SubStreamsInfo
06 kPackInfo position, number and sizes of packed streams
07 kUnpackInfo list of folders: the coder chain of each block and unpacked sizes
08 kSubStreamsInfo how many files are in each folder, their sizes and CRC-32 values
05 kFilesInfo number of files, then per-file properties
0E, 0F kEmptyStream, kEmptyFile directories and 0-byte files have no data stream
11 kName file names with relative paths, UTF-16LE, each ending with a 0 character
12, 13, 14 kCTime, kATime, kMTime creation, access, modification time (Windows FILETIME)
15 kWinAttributes Windows attributes; Unix mode in the high 16 bits when bit 0x8000 is set
00 kEnd ends the current record

Most archives created by 7-Zip have an encoded header: the 32-byte signature header points to a small 17 record, which describes an LZMA stream that unpacks to the real 01 header. With header encryption (-mhe=on) that stream is also AES-encrypted, so the file names can’t be listed without the password.

Folders, coders and solid blocks#

A folder is one block of data passed through a chain of coders (compression, filters, encryption). Files are concatenated and compressed together inside a folder. When one folder holds many files the archive is solid: better compression, but extracting one file means decompressing everything before it in the same folder. 7-Zip limits solid block size by default (-ms=on, block size depends on level); -ms=off puts each file in its own folder.

Common method IDs:

Method ID Coder
00 Copy (stored)
21 LZMA2 (default)
03 01 01 LZMA
03 04 01 PPMd (good for text)
04 02 02 BZip2
04 01 08, 04 01 09 Deflate, Deflate64
03 03 01 03, 03 03 01 1B BCJ (x86 filter), BCJ2 (x86 filter with 4 streams)
0A, 0B ARM64, RISC-V filters
03 Delta
06 F1 07 01 AES-256 + SHA-256 (encryption)

Filters like BCJ convert relative addresses in executable code to absolute ones before compression, which makes .exe and .dll files compress 10-20% better. Third-party builds (7-Zip ZS, NanaZip) add Zstandard, Brotli, LZ4 and others with their own IDs; standard 7-Zip can’t open archives that use them.

Encryption#

7z encrypts with AES-256 in CBC mode. The key is derived from the password (UTF-16LE) with 219 rounds of SHA-256. Only file data is encrypted unless the header is encrypted too. There is no authentication tag: a wrong password is usually detected by a CRC error after decompression.

Multi-volume and self-extracting archives#

Creating 7z files with the command line#

Shell
7z a archive.7z folder/                    # create, LZMA2, level 5
7z a -mx=9 archive.7z folder/              # maximum compression (slower, more memory)
7z a -ms=off archive.7z folder/            # non-solid: fast access to single files
7z a -p -mhe=on secret.7z folder/          # ask for a password, encrypt data and file names
7z a -v100m archive.7z folder/             # split into 100 MB volumes
7z x archive.7z -ooutput/                  # extract with full paths
7z l archive.7z                            # list contents
7z t archive.7z                            # test CRCs

On Linux the official 7-Zip command is 7zz (package 7zip); the older p7zip fork installs 7z.

Specifications and documentation#

Software that opens 7z files#

SoftwareWindowsmacOSLinuxWebCanNotes
SumatraPDF✓viewfree, open source; shows images inside .7z and .cb7 comic book archives as pages
Windows File Explorer✓view, createbuilt into Windows 11 (23H2 opens 7z, 24H2 creates it); no encrypted archives
7-Zip✓✓✓view, create, convertfree, open source (LGPL); the reference implementation; 7zz command line on Linux and macOS
NanaZip✓view, createfree, open source 7-Zip fork for Windows 11 with Zstandard, Brotli and other extra methods
PeaZip✓✓✓view, create, convertfree, open source GUI over 7-Zip and others
WinRAR✓viewcommercial (trial); extracts 7z, creates only RAR and ZIP
Bandizip✓✓view, createfree edition with ads, paid editions
The Unarchiver✓viewfree, extracts 7z including encrypted ones
Keka✓view, createfree, open source; also in the Mac App Store (paid)
Ark✓view, createfree, open source KDE archiver
File Roller (Archive Manager)✓view, createfree, open source GNOME archiver; needs 7-Zip or p7zip installed for 7z
ZArchiverview, createfree Android archiver. Also on Android
ezyZip✓view, convertfree, extracts 7z in the browser without uploading

Libraries#

Open-source libraries that read and write 7z archives. See all 7z libraries for a comparison.

C/C++bit7z, libarchive, LZMA SDK
C#SevenZipExtractor, SharpCompress
JavaCommons Compress
Gosevenzip
Pythonlibarchive-c, py7zr
Rubyffi-libarchive, seven-zip
Rustsevenz-rust2
PHPArchive7z