KS4J277 1.2.5 20 min read 10 question quiz 19 exam marks

Compression

Why files are compressed at all, exactly how lossy and lossless differ, and how to choose correctly between them in any scenario the exam gives you.

Why compress

Compression means reducing the size of a file.

Three reasons it matters:

  1. Less storage space is used, so more files fit on a device.
  2. Faster transmission over a network, because there is less data to send.
  3. Less bandwidth is consumed, which reduces cost and eases congestion.

Streaming video, sending email attachments, loading web pages and backing up a phone all depend on compression working well.

The exam sentence

Compressed files take up less storage space and can be transmitted more quickly, because there is less data to send.

Lossless and lossy compression compared with the original fileCompression, with the length of each bar at the bottom standing for the size of the file. The original holds every byte of the data. Lossless compression finds repetition and records it more briefly: run length encoding replaces a run of identical values with the value and a count, so six As followed by three Bs becomes 6A 3B, and Huffman coding gives the most common symbols the shortest codes. Nothing is discarded, so unpacking returns exactly the original file, bit for bit, though the saving is modest. Lossy compression throws data away permanently, such as detail the eye is unlikely to miss, and so the file becomes much smaller but the original can never be recovered. Text and program code must be lossless because one wrong byte breaks them. Photos and music can usually be lossy.OriginalLosslessLossy12 MBevery byte of the data,nothing thrown awayfinds repetition and says it shorterAAAAAABBB6A3B6 MBunpack it: identical1 MBdetail thrown awayand never coming backOriginal12 MBLossless6 MBLossy1 MB1234
  1. The original file: every byte of the data, nothing thrown away.
  2. Lossless finds repetition and records it more briefly.
  3. Unpack it and you get back exactly what you started with.
  4. Lossy throws data away permanently, and gets much smaller.
Ask what happens if one byte changes. If the answer is that it breaks, the compression has to be lossless.

Lossy compression

Lossy compression permanently removes some of the data from the file.

The data chosen for removal is data the human eye or ear is least likely to notice:

  • In audio, frequencies too high or too quiet for most people to hear
  • In images, subtle colour differences the eye cannot easily distinguish

Characteristics

  • Much greater size reduction, often to a small fraction of the original
  • Some quality is lost, and it is lost permanently
  • The original file cannot be recovered
  • Repeatedly saving in a lossy format degrades the file further each time

Where it is used

  • MP3 and AAC audio
  • JPEG images
  • MP4 video and most streaming
Lossy is irreversible

Once compressed, the removed data is gone. Saving a JPEG back as a PNG does not restore anything, it just stops further loss. This point is worth a mark.

Lossless compression

Lossless compression reduces file size without removing any data. It works by recording the data more efficiently, usually by identifying and encoding repetition.

A simple illustration

Instead of storing:

AAAAAAAABBBBCCCCCCCC

it stores:

8A 4B 8C

Every character can be reconstructed exactly. Nothing has been thrown away, the information has simply been described more compactly.

Characteristics

  • The original file is restored perfectly when decompressed
  • Less size reduction than lossy
  • No loss of quality at all

Where it is used

  • ZIP archives
  • PNG and GIF images
  • FLAC audio
  • Any file where every byte matters: program files, spreadsheets, documents, databases
Why a program must use lossless

If lossy compression removed part of a program file, the instructions would be corrupted and the program would fail to run. Text documents are the same, a missing word changes the meaning.

Choosing between them

LossyLossless
Data removedYes, permanentlyNo
Original recoverableNoYes
Size reductionLargeSmaller
QualityReducedUnchanged
Typical usesMP3, JPEG, streaming videoZIP, PNG, FLAC, program files

Choosing correctly

Ask one question: would losing some data matter?

  • Streaming a film to a phone: no, the viewer will not notice, and small files matter enormously. Use lossy.
  • Archiving a legal document: yes, absolutely. Use lossless.
  • A photographer's master copies: yes, they need to edit them later without accumulated degradation. Use lossless.
  • A photograph on a web page: no, small size and fast loading matter more. Use lossy.
How to phrase the justification

Name the type, then say what would happen if you chose the other one. "Lossless must be used because compressing a spreadsheet with lossy compression would permanently remove values, corrupting the data."

Lossless against lossy compression: a picture before and after, and when to use eachTwo ways to compress a file. With lossless compression a 5 megabyte picture is compressed to 3.2 megabytes using something like ZIP, PNG or FLAC, and when it is restored it is identical to the original, because nothing is lost. With lossy compression the same picture is compressed to 0.5 megabytes using something like JPEG, MP3 or MP4, and when it is restored it is not identical, because detail has been thrown away for good. Lossless suits text, programs, spreadsheets and medical scans, anything that must be exact. Lossy suits photos, music and video, where small losses go unnoticed and the files shrink a lot.Lossless1original5.0 MBcompressed3.2 MBrestoredidenticalZIP, PNG, FLACnothing is lost: every bit comesbackLossy2original5.0 MBcompressed0.5 MBrestorednot identicalJPEG, MP3, MP4detail is thrown away for goodWhich to use?3Losslesstext, programs, spreadsheets, medicalscans: anything that must be exactLossyphotos, music, video: small losses gounnoticed and the files shrink a lot
  1. Lossless: the file gets smaller, and decompressing gives back exactly the original.
  2. Lossy: the file gets much smaller, but detail is thrown away for good, so it cannot be restored exactly.
  3. Choose lossless when the data must be exact, and lossy when small losses do not matter.
Lossy files can never be restored to the original. That is the trade for a much smaller file.

Key terms you must be able to define

Compression
Reducing the size of a file so it uses less storage and transmits more quickly.
Lossy compression
Compression that permanently removes some data, giving a large size reduction but reduced quality.
Lossless compression
Compression that reduces size without losing any data, so the original file can be perfectly restored.
Bandwidth
The amount of data that can be transmitted over a network connection in a given time.
Decompression
Restoring a compressed file so it can be used.

Flashcards

Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.

DefineCompression
AnswerReducing the size of a file so it uses less storage and transmits more quickly.
DefineLossy compression
AnswerCompression that permanently removes some data, giving a large size reduction but reduced quality.
DefineLossless compression
AnswerCompression that reduces size without losing any data, so the original file can be perfectly restored.
DefineBandwidth
AnswerThe amount of data that can be transmitted over a network connection in a given time.
DefineDecompression
AnswerRestoring a compressed file so it can be used.

Reach the top grade on this topic

This topic is generous with marks provided you write with precision.

Say permanently. Lossy compression does not just reduce quality, it removes data permanently and the original cannot be recovered. That word is often the difference between one mark and two.

Explain the mechanism of lossless. Do not just say "no data is lost". Say that repeated patterns are identified and stored more efficiently, for example by recording a value once with a count, so the original can be reconstructed exactly.

Justify with consequences. The strongest scenario answers say what would go wrong with the wrong choice, not just what is good about the right one.

Know that lossy is not always worse. For a video streaming service, lossy is not a compromise, it is the only workable option. Answers that treat lossy as simply inferior miss the point.

  • Define both types in one sentence each, including the word permanently
  • Explain the mechanism of lossless with a short example
  • Recommend a type for any scenario and justify by naming what would go wrong otherwise
  • Give two correct real file formats for each type

Mistakes that cost marks here

Avoid these
  • Saying lossy compression 'compresses more of the file'. It removes data, which is why it achieves greater reduction.
  • Claiming a lossy file can be restored to its original quality later. It cannot.
  • Saying lossless compression 'does not reduce the file size much so it is not useful'. It is essential wherever accuracy matters.
  • Giving JPEG as an example of lossless. JPEG is lossy. PNG and GIF are lossless.
  • Recommending lossy for a text document or a program file, which would corrupt it.
Fun fact

Lossless compression works by finding repetition. This is why a text file can shrink to a fifth of its size while a file of truly random numbers barely shrinks at all: there is no pattern to exploit.

Knowledge check

0 of 10 answered
1What is the main purpose of compression?
2Which statement about lossy compression is correct?
3Which of these uses lossless compression?
4Why must a program file be compressed using a lossless method?
5How does lossless compression reduce file size?
6A user saves a photograph as a JPEG, opens it, and saves it as a JPEG again several times. What happens?
7Which is the strongest reason a music streaming service uses lossy compression?
8What happens to a lossless compressed file when it is decompressed?
9A hospital must store patient scan images for legal review. Which compression should be used?
10Which pair of formats are both lossy?
Score 0 / 10

Exam-style questions

Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.

19 marks
1State two reasons why files are compressed.2 marks
State

Mark scheme0 / 2
  • LUses less storage space
  • LFaster to transmit or download because less data is sent
Model answer

Files are compressed so that they take up less storage space on a device, allowing more files to be stored. They are also compressed so that they can be transmitted more quickly across a network, because there is less data to send, which reduces both the download time and the bandwidth used.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
2Explain the difference between lossy and lossless compression.4 marks
Explain

Mark scheme0 / 4
  • LLossy permanently removes some of the data from the file
  • LThe original file cannot be recovered after lossy compression
  • LLossless reduces size without removing any data
  • LThe original file can be perfectly restored when decompressed
Model answer

Lossy compression reduces file size by permanently removing some of the data, typically detail that the human eye or ear is unlikely to notice, such as very high frequencies in audio or subtle colour differences in an image. Because the data has been deleted, the original file cannot be recovered from the compressed version. Lossless compression reduces file size without removing any data at all, instead recording the information more efficiently by identifying repetition and encoding it compactly. When a losslessly compressed file is decompressed, the original is restored exactly, byte for byte.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
3A company needs to email a large spreadsheet containing financial records to its accountant. Explain which type of compression should be used and why.4 marks
Explain

Mark scheme0 / 4
  • LLossless compression should be used
  • LEvery value in a financial spreadsheet is significant
  • LLossy compression would permanently remove data, corrupting the records
  • LLossless still reduces the size so it is quicker to email, and the file opens exactly as it was
Model answer

The company should use lossless compression, for example by placing the spreadsheet in a ZIP archive. In a financial spreadsheet every single figure is significant, and the accountant needs the file to be exactly as it was created. Lossy compression works by permanently discarding data that is judged unimportant, and applied to a spreadsheet this would destroy or alter values, producing records that are inaccurate and legally worthless. Lossless compression still makes the file meaningfully smaller, so it attaches and sends more quickly and is less likely to hit an email size limit, but when the accountant decompresses it the spreadsheet is restored exactly as it was, with every value intact.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
4Describe how lossless compression is able to reduce the size of a file without losing any data.3 marks
Describe

Mark scheme0 / 3
  • LIt identifies repeated data or patterns within the file
  • LThe repetition is recorded more efficiently, for example storing a value once with a count
  • LThe original can be reconstructed exactly from this record
Model answer

Lossless compression works by finding repetition within the data rather than throwing anything away. The algorithm identifies patterns and sequences that occur more than once, and records them more efficiently, for example by storing a repeated value a single time together with a count of how many times it should appear, or by building an index of common sequences and replacing each occurrence with a short reference to that index. Because the record contains everything needed to rebuild the original, decompression reconstructs the file exactly as it was, so no data is lost.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
5A video streaming service compresses all of its films using lossy compression. Evaluate this decision.6 marks
Evaluate

Mark scheme0 / 6
  • LLossy gives a much greater reduction in file size than lossless
  • LSmaller files use less bandwidth, allowing streaming without buffering
  • LLess storage is needed on the servers, reducing cost
  • LSome quality is permanently lost
  • LThe removed data is chosen to be least noticeable to viewers, so the impact is limited
  • LConcludes that lossy is appropriate here, with a caveat such as keeping lossless masters
Model answer

Using lossy compression is the right decision for a streaming service. Lossy compression achieves a far greater reduction in file size than lossless could, often reducing a film to a small fraction of its original size, and this directly determines whether streaming is viable at all. Smaller files require far less bandwidth per viewer, which means films start quickly and play without buffering even on slower home connections, and it also means the service can serve many more simultaneous viewers from the same infrastructure. Storage costs fall too, since a library of thousands of films takes up a fraction of the space it otherwise would. The cost is that quality is permanently reduced and the original cannot be recovered from the compressed copy. However, lossy video compression is designed to discard the information the human visual system is least sensitive to, so on a typical television or phone screen most viewers notice little or no difference. On balance the decision is correct, because without lossy compression streaming at scale would be impossible. The service should, however, retain uncompressed or losslessly compressed master copies of each film, so that higher quality versions can be produced in future as bandwidth improves, rather than being permanently limited by today's compressed files.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
Machine mark 0 / 19