Introduction
ZIP files are a common way to compress and bundle files for storage and sharing. A simple, clever trick that often makes ZIP files noticeably smaller is to rearrange, preprocess, or choose content so similar data appears together before compression — a concept known as “data locality” or “pre-sorting.” This article explains why that works, how ZIP compression works, and practical steps you can take.
- How ZIP compression works — the basic idea
- What “the clever trick” means in plain English
- Why ordering and grouping files helps
- Common practical scenarios where this trick helps
- What does not help (and can hurt) compression
- Two simple, safe techniques you can use now
- Compression settings and tools that affect results
- Practical examples and estimated gains
- When to choose other formats than ZIP
- Balancing convenience, compatibility, and compression
- Step-by-step checklist for better ZIPs
- Limitations and realistic expectations
- Security and data integrity considerations
- Simple experiment you can try
- When the trick is not worth the effort
- Conclusion
How ZIP compression works — the basic idea
ZIP is not a single one-way magic algorithm; it is a container format that commonly uses the DEFLATE compression method. DEFLATE combines two ideas: LZ77-style dictionary matching (finding repeated sequences) and Huffman coding (assigning shorter codes to common symbols). The key to getting good compression is making it easy for the compressor to find repeated patterns and predictable symbol frequencies.
Practical consequence: when similar bytes or repeated sequences occur close together in the input stream, the compressor can reference earlier occurrences rather than storing them again. That reduces the number of bits written into the ZIP archive.
What “the clever trick” means in plain English
The clever trick is to arrange your files or their contents so that similar or repeated data is adjacent before creating the ZIP archive. That can dramatically increase repetition that the compressor detects and therefore reduces the final file size.
Examples of making data similar and adjacent:
Group many small text or CSV files with the same columns into one big file or place them next to each other inside the ZIP so the compressor can reuse patterns across file boundaries.
Merge multiple log files in chronological order rather than keeping them in separate unrelated pieces.
Store many versions of the same document or many images that are slightly different in the same folder and add them to ZIP together so shared byte sequences are easier to match.
Why ordering and grouping files helps
Compressors have a limited-size sliding window (for DEFLATE, commonly up to 32 KB). If two identical or similar sequences are separated by more than the window size, the compressor cannot reference the earlier sequence. That means the duplicate will be stored again, reducing compression efficiency.
By placing similar data next to each other you increase the chance that repeated patterns fall within the compressor’s window. This allows dictionary matches (copying back-references) to be used, which are far more space-efficient than re-encoding the same content twice.
Common practical scenarios where this trick helps
Collections of similar text files: source code files, markdown notes, CSV datasets with the same headers, and configuration files all often share repeated tokens like keywords, punctuation, or column heads. Concatenating or grouping them improves ZIP compression.
Image series with minor changes: lossless image formats like BMP or PNG may share identical headers or palette data. Storing near-duplicates together helps, although note that many image formats are already compressed (see more below).
Backups and snapshots: incremental backups that keep many versions of similar files benefit from grouping similar versions together. An archive that merges versions or keeps differential data nearby compresses more efficiently.
What does not help (and can hurt) compression
Already compressed files: formats such as JPEG, MP3, MP4, many video files, and some PNGs are already highly compressed. ZIP typically cannot reduce their size further and may sometimes slightly increase size due to archive overhead.
Random or encrypted data: truly random data or data that has been encrypted looks unpredictable to a compressor and will not compress; mixing such data with compressible data doesn’t make the compressible parts any better unless you reorder them so compressible parts are adjacent.
Large separation of similar sequences: as noted, if similar content lies outside the compressor’s window the trick fails. Also, arbitrarily concatenating many different file types without grouping by similarity can reduce effectiveness.
Two simple, safe techniques you can use now
1) Group by file type and similarity before zipping. Put text files in one folder, images of the same type in another, and add those folders to the ZIP. This is easy to do manually and works across operating systems.
2) Concatenate similar small files into a single larger file where it makes sense. For example, combine multiple small JSON or CSV files into one file (with clear separators or added metadata so you can split later). Compressing one larger file often yields better results than compressing many tiny files because the compressor sees a continuous stream of similar tokens.
How to concatenate safely
When concatenating, include a simple separator or metadata so you can reconstruct the originals later. For text formats, a unique delimiter line or a header with the original filename makes re-splitting straightforward. For binary files, use an outer container or archive format that stores offsets or lengths so you don’t corrupt boundaries.
Compression settings and tools that affect results
Compression level: most ZIP utilities let you choose a compression level (for example, “store,” “fast,” “normal,” “maximum”). Higher levels spend more CPU time but search harder for longer dictionary matches and can give better compression. For many users, the “normal” or “maximum” setting gives the best balance of time and size.
Window size and algorithms: some compressors and archive formats allow larger window sizes or different algorithms (e.g., Zstandard, Brotli, or 7z with LZMA2). A larger window can find matches farther apart, but standard ZIP with DEFLATE has a fixed window in most implementations. Consider using other formats when you need more powerful compression.
Solid archiving: some archive formats support “solid” compression, where multiple files are compressed as if concatenated without resetting the compressor between files. Solid archives often compress much better when files are similar. Standard ZIP historically resets between files, but some ZIP tools or formats provide options that emulate solidity. When cross-platform compatibility matters, test to ensure the chosen option is supported by the target tools.
Practical examples and estimated gains
Text logs: If you have 100 small log files with similar headers and repeated lines, putting them together can reduce the archive size by tens of percent compared with zipping files in arbitrary order.
Source code repositories: Grouping and zipping source code by project or language usually compresses well because code uses repeated keywords, whitespace, and comments. Expect good compression ratios compared with zipping mixed binary assets and compiled objects together.
Mixed media folders: If a folder contains both highly compressible text and already-compressed media like JPEGs, separate them. Compress text into its own ZIP and store media either without further compression or in a different archive tuned for media.
When to choose other formats than ZIP
If you need maximal compression for many similar files, consider modern alternatives:
Zstandard (zstd): fast and efficient across a range of compression levels, with support for very large dictionary sizes.
7z (LZMA/LZMA2): often achieves higher compression than standard ZIP at the cost of slower compression times.
TAR + gzip/bzip2/xz: the TAR container concatenates files, then a strong compressor (like xz or bzip2) is applied to the whole stream. This is effectively “solid” compression and frequently gives better results than zipping files individually.
Note: If you need broad compatibility with Windows users who expect .zip files, use ZIP for distribution and consider offering an alternative download (7z or tar.xz) for advanced users who want smaller files.
Balancing convenience, compatibility, and compression
ZIP is ubiquitous and easily opened on nearly every desktop and mobile platform without extra software. That convenience matters for distribution. The trick — grouping similar files and combining small text files — preserves compatibility while improving compression.
If your audience knows how to use other formats, offer both: a .zip for widest compatibility and a .7z or tar.xz for users who want smaller downloads. Clearly label what each file contains so users choose appropriately.
Step-by-step checklist for better ZIPs
1) Scan the folder to identify file types and likely compressibility (text vs. already compressed media).
2) Move or copy similar files into separate folders (e.g., logs, CSVs, source, images).
3) For many tiny text files, consider concatenating them with clear separators or creating a TAR-like single file if compatible with your workflow.
4) Use a ZIP utility with a high compression setting if time permits. Test with a sample to get a sense of time vs. size trade-off.
5) If you need even better compression and compatibility is not strictly required, create an alternative archive with 7z or tar.xz and offer both options to users.
Limitations and realistic expectations
This trick helps when there’s redundancy or similarity to exploit. If most files are independently compressed (JPEG, MP3, video) or are encrypted, you will see little benefit. Do not expect dramatic reductions in every case — improvements vary widely depending on the data.
Also, some ZIP implementations may reset compression state between files, which reduces cross-file matching. When possible use tools/options that compress multiple files in a single stream or create an archive format designed for solid compression.
Security and data integrity considerations
When concatenating files or changing file layouts, preserve originals until you verify the archive and any re-splitting process. If files are sensitive, encrypting the resulting archive is often better than encrypting individual files with ad hoc methods. Use well-supported encryption options provided by mainstream tools and keep in mind compatibility differences.
Simple experiment you can try
Create a folder with 100 small text files that share common headers or repeated lines. Zip them as-is and note the size. Then concatenate the files into one large text file (adding a visible separator line between each), zip the concatenated file, and compare sizes. You should see noticeably better compression for the concatenated version because the compressor can exploit repeated patterns across the whole stream.
When the trick is not worth the effort
If you are distributing mostly media files and need the widest possible compatibility, reorganizing files likely yields minimal gains and may confuse users. In those cases, keep things simple: use ZIP with “store” or default settings and avoid complexity, or provide uncompressed bundles when integrity and speed matter more than size.
Conclusion
The clever trick that makes ZIP files smaller is fundamentally about improving data locality so a compressor can find repeated patterns within its working window. By grouping similar files, concatenating many small text files, or using solid compression formats, you give the compressor more opportunities to reuse data and reduce archive size. The technique is straightforward, broadly safe, and especially effective for text, logs, source code, and other highly repetitive content; it offers diminishing returns for already-compressed or encrypted files.

