Photos, songs and videos are big, and big files are slow to send and fill up storage. Compression makes them smaller, either by throwing away data you are unlikely to miss or by storing the same data more cleverly.
Compression reduces the size of a file, so it needs less storage space, less bandwidth and a shorter transmission time. Lossy compression permanently removes data, for example by reducing the resolution or colour depth of an image, or the sample rate or resolution of a sound; the original cannot be recovered. Lossless compression reduces the size without permanent loss of data, so the original file can be rebuilt exactly; run length encoding (RLE) is an example.
Fig. 1: RLE stores each run of identical values as a count and the value
Section 01
Why compress?
Smaller files help everyone who stores or sends them. Learn the three benefits the syllabus names.
Less storage space: more files fit on a device or in cloud storage.
Less bandwidth: sending the file uses less of the network's capacity, which matters for streaming.
Shorter transmission time: files upload, download and attach to emails faster.
Examiner trap
"It makes the file smaller" only restates compression. For a mark, give the effect: less storage, less bandwidth or a shorter transmission time.
Section 02
Lossless: run length encoding.
In the lab, type some text or paint a 1-bit image and watch RLE replace each run of identical values with a count and the value. Then decode it again.
How RLE works: a run of the same character or pixel colour is stored once, with the number of times it repeats.
Lossless: decoding rebuilds the original exactly, so RLE suits text, program files and simple images.
Works best on data with long runs of repeated values; with little repetition the "compressed" file can be bigger.
Worked example Encode and count
Use RLE to encode WWWWWWWWBBBWWWW. If each count and each character take 1 byte, how many bytes are saved?
Runs: 8 W, then 3 B, then 4 W.
Encoded: 8W 3B 4W, which is 3 pairs = 6 bytes.
Original: 15 characters = 15 bytes.
Saved: 15 − 6 = 9 bytes.
Answer: 8W 3B 4W; 9 bytes saved
Your turn
Decode the RLE data 3R 2G 5B.
RRRGGBBBBB (10 characters)
Examiner trap
RLE does not always make a file smaller. ABCD encodes as 1A 1B 1C 1D, which is twice as long.
Stage 1 · Learn
Check what the sim just showed you
Four quick checks. Each correct answer earns XP and records this skill on your profile.
Quick check+10 XP
What is lossless compression?
Quick check+10 XP
Which of these is an example of lossless compression?
Quick check+10 XP
Why can a file compressed with lossy compression not be restored to the original?
Quick check+10 XP
In the lab, why does RLE make the text ABCDEF bigger?
Section 03
Lossy: data is gone.
Switch the lab to lossy mode and reduce the resolution, colour depth or sample rate. The file shrinks, but undoing it cannot bring back the detail.
Lossy
Lossless
Data
permanently removed
none permanently lost
Original recovered?
no
yes, exactly
Methods
reduce image resolution or colour depth; reduce sound sample rate or resolution
run length encoding (RLE)
File size
usually much smaller
smaller, but usually less reduction
Suits
photos, music and video, where small losses are hard to notice
text, program code, spreadsheets, where every bit matters
Examiner trap
Never choose lossy compression for text or program files: a lost character or instruction changes the meaning or stops the program working.
Stage 2 · Exam
Exam-style questions
Unlocks once the four checks above are done. Worth more XP, written to IGCSE Paper 1 standard.
Finish the four checks above to unlock the exam questions
Exam style+20 XP
Which is a lossy compression method for an image?
Exam style+20 XP
Which is a benefit of compressing a file before sending it?
Exam style+20 XP
What is the RLE encoding of GGGGGHHH?
Exam style+20 XP
Which file should be compressed with lossless compression?
Skill unlocked
Compression, mastered.
This skill is now recorded on your profile. Keep the chain going.