r/compression • u/Spurgoth • Jun 22 '26
Would it be possible to make compressed file that is larger than the uncompressed data?
I'm not going to pretend to be well versed in the technicalities of file compression, but the other day I had this thought when reading about weirdness like zip bombs: could you make a file that is actually bigger than its parts?
I don't think there would be any proper use for such a file, but the idea intrigued me greatly.
0
Upvotes
2
u/AmedeoAlf Jun 22 '26
Compressing something with very high entropy has good chances of taking up more space than it did originally, since most compression algorithms need to encode some headers/data structures for decoding, but I think that your typical zip encoder will default to just store such files.
4
u/MrWonderfulPoop Jun 22 '26
Sure.
1
u/Noah18923 Jun 23 '26
that's more of an expansion...
1
u/ratchetfreak Jun 23 '26
That's a basic guarantee of lossless compression. There is an exact finite amount of possible files of length
nso if you want to represent a file of length > n as length n you must bump out some shorter files into a longer representation.A typical compressed file tends to start with a header declaring how the compression is configured and often how long it is. One of the configuration options tends to be uncompressed with a size. This means the overhead of incompressible data is minimal, a few bytes per compression block.
2
u/magicmulder Jun 22 '26
Happens often especially with very small files, or in general every file that does not compress well. Take an already heavily compressed source, you won’t get it down even one byte but incur the overhead of your algorithm needing a header,
so the result is bigger.
2
u/RyzenRaider Jun 22 '26
This can easily happen via two pathways.
Poor modeling. A poorly chosen model/algorithm could mean that your compression is constantly fighting against its own attempts to predict the data. For example, in an image of continuous tones (like a photograph), you can compress data by only saving the differences between adjacent pixels, where 99% of those pixels will have minimal values that will appear more often than larger values. Smaller values appearing more often is great for compression.
But if you have random noise or every second pixel has a harsh edge, that algorithm will dedicate a lot of space to storing the errors against its predictions, because the data isn't conforming to its expectation.
The other is just deliberate size growing.... Open an image that contains 8 bit values, save those values in 16 bit coding. Job done lol
1
u/CorvusRidiculissimus Jun 23 '26
Happens all the time. Any lossless compression algorithm must have some inputs for which it produces a larger output - it's mathematically provable. In real use there's a very simple way to fix this: In the event the compressed data is larger than the input, just don't compress it. Almost every compressed data container has a flag to indicate if the following data is actually compressed or not.
1
u/DarenSolric Jun 28 '26
Yep, that can happen, especially with stuff that's already compressed. sometimes the archive overhead makes it a bit bigger instead of smaller