StudyVault
Home Unit Overview Exam Technique Revision Techniques ← Previous Lesson Next Lesson →

← Back to Dashboard

Overlay:
0:00 / 0:00 Narration generated using AI text-to-speech.

Data Compression

Why We Compress Files

Modern files can be enormous. A single high-quality photo, song or video can take up millions of bytes, and moving all of that data across a network takes time and uses up capacity. Compression is the answer: it shrinks a file so it uses less storage space and travels faster. Compressed files download and upload more quickly, they use less bandwidth, web pages containing them load sooner, and more of them fit inside an email attachment limit or a backup drive. In short, compression saves both space and time.

Key Fact

Files are compressed to save storage space and to move them faster over a network. Everyday examples include streaming music and video, sending email attachments, loading images on a web page, and backing up large amounts of data.

Two Families: Lossless and Lossy

There are two main approaches to compression, and the difference between them comes down to a single question: is any of the original data thrown away? A lossless method keeps every bit; a lossy method deletes some data for good. Choosing between them is one of the most important decisions when storing or sending a file.

Lossless Compression

Lossless compression makes a file smaller without losing any information at all. It works by spotting redundancy — data that is repeated or predictable — and recording it in a more efficient way. A matching program can then reverse the process and reconstruct the original file perfectly. Because nothing is thrown away, lossless compression is essential wherever every character matters, such as text documents, spreadsheets and program files. Familiar lossless formats include ZIP archives, PNG images and FLAC audio.

The trade-off is that lossless compression usually cannot shrink a file as much as lossy compression can, because it is only allowed to reorganise data, never to remove it. What you gain is certainty: the restored file is identical to the one you started with.

One simple lossless method is run-length encoding. Instead of listing a run of the same value over and over, it stores the value once together with a count of how many times it repeats. A line of forty identical white pixels can be recorded as ‘white, 40’ rather than writing ‘white’ forty times. This works brilliantly on images with large blocks of a single colour, but poorly on detailed photographs where colours rarely repeat.

Another method is Huffman coding, which gives the most common characters the shortest binary codes and the rarer ones longer codes, so the whole file needs fewer bits overall. Both methods are fully reversible, and that reversibility is exactly what makes them lossless.

Key Fact

Lossless compression loses no data. The original file can be rebuilt perfectly, bit for bit, which is why it is used for text, spreadsheets and program code where a single wrong character could ruin the file.

Lossy Compression

Lossy compression takes a bolder approach: it permanently removes some of the data to make the file far smaller. The detail it discards is chosen carefully — usually parts that humans are unlikely to notice. The catch is that once this data is gone, it is gone for good, so the original file can never be recovered exactly.

Lossy compression is ideal for photos, music and video, where a small drop in quality is a fair price for a huge saving in size. JPEG images and MP3 audio are the best-known examples. An MP3, for instance, removes sounds that are hard for the human ear to pick out, such as very quiet notes that are drowned out by louder ones, shrinking a song to a small fraction of the size of the uncompressed original.

With lossy compression you choose a balance between file size and quality. Compress a little and the loss is almost invisible; compress heavily and pictures turn blocky or blurry and audio sounds muddy. The right amount depends on how the file will be used.

Because the process is not reversible, editing a lossy file and re-saving it as lossy again removes even more detail, so quality gets steadily worse with each save. This is why photographers and musicians keep a lossless or uncompressed master copy and only export a lossy version at the very end.

Choosing the Right Type

The safest way to decide is to ask whether losing any data would matter. For a legal document, a spreadsheet of exam marks or a program’s code, you must use lossless compression, because a single changed value could corrupt the whole file. For photographs on a website, music streaming or a video call, lossy compression is usually the better choice: the enormous size saving matters more than perfect detail, and the loss is hard to notice anyway.

Key Fact

Lossy compression makes a much smaller file but permanently loses some detail, so the original cannot be recovered. Lossless compression saves less space but keeps every bit, so the original can always be restored exactly.

Practice Questions

Test yourself on this lesson. Pick a question, write your answer, then get it marked.

AI feedback
AI feedback is guidance, not a final exam mark. If you disagree, your teacher's view is always the tie-breaker.
← Back to unit
Video

© 2026 StudyVault · About · FAQ · Copyright & IP · Privacy · Disclaimers

StudyVault Education Ltd · registered in England and Wales, company no. 17490559 · 71–75 Shelton Street, London WC2H 9JQ