You compress a folder of photos and songs, and the archive comes out almost the same size. Sometimes it is a few bytes larger. Nothing is broken. Compression can only remove patterns, and some files have none left to remove.

This guide explains the two reasons behind it: data that has already been compressed, and a counting argument that no method can escape. You will learn how to predict which files will resist, how to read the result, and what to do instead.

When the pattern is already gone

A compressor shortens data by finding repeats and predictable parts. If an earlier step already squeezed those out, the next compressor finds little. Many common formats include such a step.

Format What already happened to the data Where it is documented
JPEG Quantization, then an entropy encoder (Huffman or arithmetic coding) ITU-T T.81
PNG Filtering, then DEFLATE compression PNG specification
ZIP A method chosen per file; DEFLATE is the default in most ZIP programs PKWARE APPNOTE
gzip DEFLATE RFC 1952
FLAC Prediction, then residual coding RFC 9639

For JPEG, the standard says the quantized values are passed to an entropy encoding procedure that compresses the data further. That final stage is the same kind of work a general-purpose compressor would do. This does not prove that zipping a JPEG gains nothing. It means the data has less pattern left, and the only reliable test is to compare sizes.

The counting argument

There is a deeper limit that applies to every lossless method. A lossless compressor must give each input its own output, or the decoder could not tell the inputs apart. Count the possibilities.

Bits in the input Inputs of exactly that length Shorter strings available (including the empty one)
3 8 7
8 256 255
16 65,536 65,535

At every length there is always one more input than there are shorter outputs. So at least one input cannot get shorter. The DEFLATE specification summarizes it this way: a simple counting argument shows no lossless algorithm can compress every possible input. A university lecture on the pigeonhole principle reaches the same result and concludes there is no perfect compression function.

Worked example. Take all 16-bit strings: 65,536 of them. Suppose you want a method that shortens a string by at least 8 bits, so the output has 8 bits or fewer. The strings of 0 to 8 bits number 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 = 511. So at most 511 of the 65,536 inputs can be shortened that much, which is 511 ÷ 65,536 = 0.78%. A Princeton lecture gives the same idea at a larger scale: of all 1,000-bit strings, only 1 in 2^499 can be encoded in 500 bits or fewer.

The argument also shows that if some inputs shrink, others must stay the same or grow. Real compressors bet that the data you give them is the kind with patterns. Data that does not fit the bet is the unlucky case.

What the formats do about it

Good formats plan for the unlucky case. DEFLATE has a stored block type that copies bytes with no compression, and the RFC puts the worst-case growth at 5 bytes per 32K-byte block, about 0.015% for large data. ZIP lists a stored method, number 0, for files copied in uncompressed. FLAC's specification says that when no usable predictor can be found for a subblock, the signal is stored uncompressed.

So a well-built tool should not make a pattern-free file much bigger. It can still end up slightly larger, because of those few bytes of block headers and file framing.

How to tell before you try

Check the format first. If the file is a JPEG, PNG, FLAC, ZIP or similar, part of the pattern has already been used up, so a further saving may be small. For anything else, compress a copy and compare.

Worked example. Example sizes: a 4,200,000-byte photo archive compresses to 4,190,000 bytes. Ratio: 4,200,000 ÷ 4,190,000 = 1.002:1. Percent saved: (1 − 4,190,000 ÷ 4,200,000) × 100 = 0.24%. Space saved: 10,000 bytes. Enter the two sizes in the compression ratio calculator to check. A saving this small says the method found almost nothing to remove.

If the saving is tiny, another pass is unlikely to do better, for the reason given in the first common mistake below.

What actually helps

  • Use a lossy format where it is acceptable. Lossy methods discard detail instead of looking for patterns. See lossless vs. lossy compression.
  • Reduce what you store. Fewer pixels, shorter audio or a lower bitrate shrink the data itself. The audio file size calculator and the image file size calculator show how those choices change the size.
  • Pick a format suited to the content. RFC 1951 says DEFLATE does not try to compress specialized data, such as raster graphics, as well as the best specialized algorithms.

Common mistakes

  • Compressing again and again. If every pass shrank a file, you could compress anything down to nothing. A Princeton lecture uses exactly that argument to show it is impossible.
  • Trusting claims that any data can be compressed. A method that shrinks all inputs, or random data by huge factors, contradicts the counting argument.
  • Blaming the settings. No setting can create pattern that is not there. Try a different kind of method only if the change in quality is acceptable.
  • Ignoring the framing. A tiny gain on a small file can vanish once headers are counted. See how ZIP files work.
  • Calling a tiny saving a failure. A small saving can still add up across many files. It only shows the data had little redundancy. For more on patterns, see how repeated patterns let files shrink.

FAQ

Why did my file get bigger after compressing?

Compressed formats add headers and checks. If the data has no pattern to remove, those extra bytes can outweigh any saving. The DEFLATE specification puts its own worst case at about 0.015% for large inputs.

Can random data be compressed?

Not in general. A Princeton lecture calls one million pseudo-random bits a difficult file to compress. The counting argument shows that only a tiny fraction of inputs can be shortened a lot.

Is there a method that compresses everything?

No. Any lossless method that shortens some inputs must leave others the same length or longer.

Will zipping a JPEG make it smaller?

It might shrink slightly or not at all. The JPEG process already includes an entropy coding stage, so there is less pattern left. Compress a copy and compare the sizes.

Sources

  1. Princeton University, Sedgewick and Wayne, 5.5 Data Compression (Algorithms lecture slides). Accessed November 6, 2026.
  2. Stanford University, Mathematical Logic Part One (CS103 lecture slides on the pigeonhole principle and compression). Accessed November 6, 2026.
  3. IETF, RFC 1951: DEFLATE Compressed Data Format Specification version 1.3. Accessed November 6, 2026.
  4. IETF, RFC 9639: Free Lossless Audio Codec (FLAC). Accessed November 6, 2026.
  5. ITU-T (copy hosted by W3C), Recommendation T.81: Digital compression and coding of continuous-tone still images. Accessed November 6, 2026.
  6. PKWARE, APPNOTE.TXT: .ZIP File Format Specification, version 6.3.10. Accessed November 6, 2026.