What Is ZIP?
ZIP is a lossless data compression and archiving format created by Phil Katz and Gary Conway in 1989. It was designed as an open format to replace ARC and PKZIP became the dominant implementation. The specification was published by PKWARE and has been extended many times; the current version is APPNOTE.TXT 6.3.10 (2023). ZIP is now natively supported by every major operating system — Windows, macOS, Linux, iOS, Android — making it the most universally compatible archive format on earth.
ZIP is unusual among archive formats in that it stores files independently — each file in the archive is compressed and stored with its own metadata, without requiring the entire archive to be decoded to extract a single file. This design trades compression ratio for random access.
ZIP Architecture: Internal Structure
A ZIP file is structured as follows:
[Local file header 1] [File data 1]
[Local file header 2] [File data 2]
...
[Local file header N] [File data N]
[Data descriptor (optional)]
[Archive decryption header (optional)]
[Central directory]
[Central directory entry 1]
[Central directory entry 2]
...
[End of central directory record]
The central directory at the end of the file is the key innovation: it is an index of all files in the archive with their offsets. ZIP readers first seek to the end of the file, find the end-of-central-directory record, then jump to each file's offset as needed. This enables:
- Random access: extract file N without reading files 1 through N-1.
- Streaming append: add files to the end and update the central directory.
- Self-extracting archives: prepend an EXE header before the ZIP data — the central directory offset is still found from the end.
Compression Methods
Each file in a ZIP archive can use a different compression method:
| Method | Code | Description |
|---|---|---|
| Stored | 0 | No compression — raw bytes |
| Shrunk | 1 | LZW variant (obsolete) |
| Imploded | 6 | Old PKZIP algorithm (obsolete) |
| Deflated | 8 | zlib/DEFLATE — the standard, ~95% of ZIPs |
| Deflate64 | 9 | Extended window (PKWARE proprietary) |
| BZIP2 | 12 | Better ratio than DEFLATE, slower |
| LZMA | 14 | 7-Zip LZMA — good ratio, rarely used in ZIP |
| Zstandard | 93 | Modern, fast, good ratio (recent addition) |
| XZ | 95 | LZMA2 (recent addition) |
Stored is used for already-compressed data (JPEG, PNG, MP4, PDF) — re-compressing them wastes CPU without saving space.
Deflated is the universal default — supported everywhere, reasonable ratio, fast.
ZIP64 Extensions
The original ZIP format used 32-bit fields, limiting:
- File size to 4 GB (2³² − 1 bytes)
- Archive size to 4 GB
- Number of files to 65,535
ZIP64 (introduced in PKZIP 4.5) extends these fields to 64 bits:
- File size up to 18 EB (2⁶⁴ − 1 bytes)
- Archive size up to 18 EB
- Number of files up to 4.29 billion
ZIP64 is triggered automatically by modern tools when any limit is exceeded. Most ZIP readers support it, but some legacy tools (including Windows XP Explorer) do not.
Encryption in ZIP
ZIP supports two encryption schemes:
Traditional PKZIP encryption (ZipCrypto): a stream cipher using a 96-bit key derived from the password. Severely weak by modern standards — known-plaintext attacks can recover the key with ~12 bytes of known content. Do not use for sensitive data.
AES encryption (WinZip/APPNOTE AES extension): AES-128 or AES-256 with PBKDF2 key derivation and HMAC-SHA1 authentication. Secure when using a strong password. Uses compression method = 99 as the marker.
# zip with AES-256 on Linux (requires zip >= 3.0)
zip -e --password "strong-password" archive.zip files/
# 7-zip AES-256 in ZIP container
7z a -tzip -mem=AES256 -p"strong-password" archive.zip files/
Note: the file names and directory structure in a ZIP archive are NOT encrypted even with AES encryption — only the file contents are. Use 7z format with AES for full encryption including filenames.
Multi-Volume (Split) Archives
ZIP supports splitting archives across multiple files:
archive.z01 (first part)
archive.z02
archive.z03
archive.zip (last part — contains the central directory)
# Create split archive (100 MB parts)
zip -s 100m archive.zip largefile.iso
# Combine and extract
zip --fix archive.zip
unzip archive.zip
ZIP in Software Distribution
ZIP is the container of choice for distributing multi-file software packages because:
- JAR (Java Archive): a ZIP containing Java
.classfiles, resources, andMETA-INF/MANIFEST.MF. - WAR (Web Application Archive): a ZIP containing a Java web app.
- APK (Android Package): a ZIP containing the Android app's DEX bytecode, resources, and signature.
- DOCX / XLSX / PPTX: Office Open XML — a ZIP containing XML files and assets.
- EPUB: a ZIP containing XHTML, CSS, and images.
- ODF (.odt, .ods, .odp): OpenDocument Format — a ZIP with XML files.
- XPI: Firefox extensions.
- VSIX: Visual Studio extensions.
- wheel (.whl): Python package distribution format.
To inspect these: rename to .zip or use unzip -l file.docx.
Command-Line Usage
# Create ZIP
zip archive.zip file1.txt file2.txt
zip -r archive.zip directory/ # recursive
zip -9 archive.zip files/ # max compression
# Extract
unzip archive.zip
unzip archive.zip -d /output/dir/ # to specific directory
unzip -p archive.zip file.txt # pipe to stdout
# List contents
unzip -l archive.zip
# Test integrity
unzip -t archive.zip
# Add/update file in existing ZIP
zip archive.zip newfile.txt
# Delete file from ZIP (requires zipnote or repack)
zip -d archive.zip unwanted.txt
Cross-platform: Windows 10+ has native zip/unzip via File Explorer and PowerShell:
Compress-Archive -Path .\files\ -DestinationPath archive.zip
Expand-Archive -Path archive.zip -DestinationPath .\output\
ZIP Vulnerabilities
Zip Slip: a path traversal vulnerability where archive entries contain ../ sequences, causing extraction to write files outside the target directory. Always sanitize entry paths before extraction.
Zip Bomb: a ZIP containing a small compressed file that expands to enormous size (e.g., 42.zip is 42 KB compressed → 4.5 PB uncompressed). Mitigate by tracking uncompressed size during extraction.
Password recovery: ZipCrypto-encrypted archives can be brute-forced rapidly. John the Ripper and Hashcat support ZIP password cracking.
ZIP vs. Other Archive Formats
| Format | Compression | Encryption | Random access | Solid archive | Unicode filenames |
|---|---|---|---|---|---|
| ZIP | Deflate/etc. | ZipCrypto, AES | Yes | No | UTF-8 (modern) |
| 7z | LZMA2 | AES-256 | Yes (partial) | Yes | Yes |
| TAR.GZ | DEFLATE | No (separate) | No | Yes | Yes |
| TAR.BZ2 | BZIP2 | No | No | Yes | Yes |
| RAR | RAR4/5 | AES-256 | Yes | Yes | Yes |
| XZ | LZMA2 | No | No | Yes | N/A |
ZIP's universal compatibility makes it the default for consumer distribution; 7z/XZ win on compression ratio.
Best Practices
- Use Stored method for already-compressed files (JPEG, MP4, ZIP) to avoid wasting CPU.
- Use AES-256 encryption (not ZipCrypto) for any sensitive archive.
- Enable ZIP64 when files or archives may exceed 4 GB.
- Sanitize entry paths during extraction to prevent Zip Slip attacks.
- Set a size limit during extraction to prevent Zip Bomb denial-of-service.
- Use
-rrecursive when zipping directories to preserve the full tree. - Preserve permissions with
zip -Xor use TAR for Unix permission sets. - Use UTF-8 flag in modern tools to avoid filename encoding issues across platforms.
- Test integrity with
unzip -tbefore distributing archives. - For maximum compression of non-ZIP-native content, consider 7z LZMA2 instead.
Related conversions
Archive format conversions used most often: