MyLeoNes™

How compression makes files smaller — Computing, 14–17

Compression removes repeated or less important information so a file needs fewer bits. Lossless compression keeps the exact original; lossy compression trades some detail for a much smaller file.

Shorter ways to say the same

Compression looks for a shorter description of data. If a text repeats “ha” many times, a code can record the pattern and its count instead of every copy. For sound or images, a lossy method may also discard details people are unlikely to notice. The decoder rebuilds the usable file.

Why compress at all?

Files became much larger when people started storing photos, music and video, while storage and internet connections remained limited or expensive. Compression reduces the space on a disk and the time needed to send a file. The problem is choosing how much detail can be removed without making the result unacceptable.

A simple run-length example

Take the string AAAABBBCCDAA, which has 12 characters. Instead of storing every character, write 4A3B2C1D2A: the number followed by the repeated symbol. This is 10 symbols before counting the digits, so it is only a modest saving here; on a long run of 100 As, the saving is much larger.

Smaller is not always better

A smaller file may sound or look worse, because lossy compression has thrown away information. It is reasonable to assume that a file with the same name is unchanged, especially when the difference is hard to see at first. Lossless compression is different: it can reduce size only where the data contains patterns to exploit.

Compression in ordinary life

JPEG photographs, MP3 or AAC audio, streaming video and ZIP archives all use compression, though they make different choices about what to keep. A messaging app may shrink an image so it sends quickly, while a scientist may choose a lossless format so measurements stay exact. The right method depends on the purpose.

Keep exploring

Other languages

Loading MyLeoNes™…