Skip to main content
ZIP is one of the most widely used archive formats, offering broad compatibility across all operating systems and applications.

Format Overview

The ZIP format provides:
  • Universal compatibility - Supported by virtually all platforms
  • Multiple compression methods - Deflate, BZip2, LZMA, and more
  • ZIP64 support - Files up to 16 exabytes
  • Strong encryption - AES-256 and WinZip AES
  • Split archives - Multi-volume support
  • Self-extracting - Create executable archives

Format Structure

According to source/CPP/7zip/Archive/Zip/ZipHeader.h, ZIP archives use the following structure:
[Local File Header + File Data + Data Descriptor] ...
[Central Directory Header] ...
[ZIP64 End of Central Directory Record]
[ZIP64 End of Central Directory Locator]
[End of Central Directory Record]

Signature Constants

From source/CPP/7zip/Archive/Zip/ZipHeader.h:13-23:
namespace NSignature {
  const UInt32 kLocalFileHeader   = 0x04034B50;
  const UInt32 kDataDescriptor    = 0x08074B50;
  const UInt32 kCentralFileHeader = 0x02014B50;
  const UInt32 kEcd               = 0x06054B50;  // End of Central Dir
  const UInt32 kEcd64             = 0x06064B50;  // ZIP64 ECD
  const UInt32 kEcd64Locator      = 0x07064B50;  // ZIP64 Locator
}
All multi-byte values in ZIP format use little-endian byte order.

Compression Methods

The ZIP format supports numerous compression methods (ZipHeader.h:37-68):

Standard Methods

  • Store (0) - No compression
  • Deflate (8) - Most common, good speed/ratio balance
  • Deflate64 (9) - Enhanced Deflate
  • BZip2 (12) - Better compression than Deflate
  • LZMA (14) - Excellent compression ratio

Advanced Methods

  • XZ (95) - LZMA2-based compression
  • PPMd (98) - Context modeling compression
  • Zstd (20, 93) - Modern fast compression
  • WavPack (97) - Audio compression
  • JPEG (96) - Image compression

Encryption Methods

  • ZipCrypto - Legacy weak encryption (not recommended)
  • WzAES (99) - AES encryption with authentication
ZipCrypto encryption is cryptographically weak and should not be used for sensitive data. Always use WzAES (AES-256) encryption for security.

Usage Examples

Create Standard ZIP Archive

7z a -tzip archive.zip files/
Uses Deflate compression by default.

Create ZIP with Maximum Compression

7z a -tzip -mm=Deflate -mx=9 archive.zip files/
Parameters:
  • -tzip - ZIP format
  • -mm=Deflate - Deflate compression method
  • -mx=9 - Maximum compression level

Create ZIP with LZMA Compression

7z a -tzip -mm=LZMA archive.zip files/
Provides better compression ratio but less compatibility.
ZIP archives with LZMA compression require 7-Zip or compatible software to extract. Standard ZIP utilities may not support this method.

Create Encrypted ZIP Archive

7z a -tzip -mem=AES256 -p archive.zip files/
Parameters:
  • -mem=AES256 - Use AES-256 encryption
  • -p - Prompt for password

Create Split ZIP Archive

7z a -tzip -v100m archive.zip files/
Creates: archive.zip, archive.z01, archive.z02, etc.

Create Self-Extracting Archive

7z a -tzip -sfx archive.exe files/

ZIP64 Format

ZIP64 extensions allow archives to exceed original ZIP limitations:
FeatureOriginal ZIPZIP64
Archive size4 GB16 EB
File size4 GB16 EB
Number of files65,535~4 billion
From ZipHeader.h:31-33:
const unsigned kEcd64_MainSize = 44;
const unsigned kEcd64_FullSize = 12 + kEcd64_MainSize;
const unsigned kEcd64Locator_Size = 20;
7-Zip automatically uses ZIP64 format when needed. You don’t need to specify it explicitly.

Version Requirements

Different ZIP features require minimum extraction versions (ZipHeader.h:72-82):
const Byte kExtractVersion_Default = 10;      // 1.0
const Byte kExtractVersion_Dir = 20;          // 2.0
const Byte kExtractVersion_Deflate = 20;      // 2.0
const Byte kExtractVersion_Deflate64 = 21;    // 2.1
const Byte kExtractVersion_Zip64 = 45;        // 4.5
const Byte kExtractVersion_BZip2 = 46;        // 4.6
const Byte kExtractVersion_Aes = 51;          // 5.1
const Byte kExtractVersion_LZMA = 63;         // 6.3

File Attributes

Host Operating Systems

ZIP format tracks the OS where the file was created (ZipHeader.h:155-180):
  • FAT (0) - MS-DOS, Windows
  • Unix (3) - Unix, Linux, macOS
  • NTFS (11) - Windows NT
  • VFAT (14) - Windows 95/NT
  • OSX (19) - macOS

Extra Fields

ZIP supports various extra data fields (ZipHeader.h:86-102):
  • Zip64 (0x01) - ZIP64 extended information
  • NTFS (0x0A) - NTFS timestamps and attributes
  • Unix Time (0x5455) - Unix timestamp
  • Unicode Name (0x7075) - UTF-8 filename
  • WzAES (0x9901) - AES encryption parameters

File Flags

From ZipHeader.h:136-142:
const unsigned kEncrypted = 1 << 0;              // Bit 0: Encrypted
const unsigned kDescriptorUsedMask = 1 << 3;    // Bit 3: Data descriptor
const unsigned kStrongEncrypted = 1 << 6;        // Bit 6: Strong encryption
const unsigned kUtf8 = 1 << 11;                  // Bit 11: UTF-8 encoding

Advanced Features

Preserve Unix Permissions

7z a -tzip -snl archive.zip files/
The -snl option stores symbolic links.

Exclude Files by Pattern

7z a -tzip archive.zip files/ -x!*.tmp -x!*.log

Update Existing Archive

7z u archive.zip newfile.txt
Only adds or updates changed files.

List Archive Contents

7z l archive.zip
Shows detailed information about archived files.

Test Archive Integrity

7z t archive.zip

Implementation Details

The ZIP handler is implemented in:
source/CPP/7zip/Archive/Zip/
├── ZipHandler.cpp      # Archive reading
├── ZipHandlerOut.cpp   # Archive creation
├── ZipIn.cpp          # Input processing
├── ZipOut.cpp         # Output processing
├── ZipHeader.h        # Format constants
├── ZipItem.h          # Item structures
└── ZipUpdate.cpp      # Archive updating

Compression Level Comparison

Deflate Compression

LevelSpeedRatioUse Case
-mx=1Fastest~40%Quick backup
-mx=5Fast~50%General use (default)
-mx=7Medium~55%Better compression
-mx=9Slow~60%Maximum Deflate

Method Comparison (1 GB mixed files)

MethodTimeSizeCompatibility
Store10s1000 MBUniversal
Deflate60s450 MBUniversal
Deflate6475s430 MBGood
BZip2120s400 MBGood
LZMA180s350 MBLimited
Performance varies significantly based on data type. Text files compress better than binary data or already-compressed formats.

Compatibility Notes

Universal Compatibility

For maximum compatibility across all platforms:
7z a -tzip -mm=Deflate -mx=5 archive.zip files/

Windows Compatibility

Windows Explorer can open ZIP files with:
  • Store (0)
  • Deflate (8)
  • No encryption or WinZip AES

macOS/Linux Compatibility

Most Unix tools support:
  • Store, Deflate, Deflate64
  • BZip2 with proper libraries

Limitations

Be aware of these ZIP format limitations:
  • No solid compression (each file compressed independently)
  • Limited recovery information
  • Weak legacy encryption (ZipCrypto)
  • Some methods have limited tool support

Best Practices

For Sharing

Use Deflate compression with -mx=5 to -mx=7

For Security

Use AES-256 encryption: -mem=AES256 -p

For Size

Use LZMA method if recipients have 7-Zip

For Speed

Use Deflate with -mx=1 for fast compression

See Also

Build docs developers (and LLMs) love