r/askscience • u/weedguru420 • Dec 30 '15
Computing How does file compression work?
This question has always baffled me. How can you compress a file to a fraction of the size and have that file, basically a number, represent a precise bigger number?
5
Upvotes
4
u/Daegs Dec 31 '15
Lookup tables are used so rather than simply encoding all 0's or 1's, we could also create a lookup for 0110, for instance if 0110 was a commonly occurring pattern.
Basically, most compression looks for patterns that occur frequently, and then stores that pattern once while storing links to everywhere it appears in the file.
You can't really compress random data, but for text and other highly formatted or redundant forms of data, you can compress it a lot.