📁 Paper 2 · 3.3 Data Representation
3.3.8a Lossless Compression
AQA 8525 · GCSE Computer Science · ~10 min read
Notes
──
Video
──
Worksheet
──
Quiz

Why Compress Files?

Compression reduces the size of a file. Smaller files require less storage space and transfer faster over networks. There are two types of compression: lossless and lossy. This lesson covers lossless.

Lossless Compression

In lossless compression, the original data can be perfectly reconstructed from the compressed file — no data is permanently removed. Decompressing the file gives back exactly the original data, bit for bit.

Lossless compression is essential when every bit of the original must be preserved, for example text files, executable programs, medical images, and source code.

Run-Length Encoding (RLE)

Run-Length Encoding (RLE) is a simple lossless algorithm that replaces runs of repeated values with a count-value pair.

AAABBBCCCCDDEEEE3A3B4C2D4E
16 characters → 10 characters (saving 6 characters)
Bitmap row (colours as letters): WWWWWWWWBBBBGGWW
W W W W W W W W B B B B G G W W
8W 4B 2G 2W
16 values → 8 values (4 pairs). Works well on flat-colour images like logos and pixel art.

When RLE works well

RLE gives the best compression ratio when data contains many consecutive repeated values — for example:

  • Images with large solid-colour areas (logos, icons, diagrams)
  • Simple graphics like clipart

When RLE works poorly

RLE can actually increase file size when data has very few repeated values — for example, a photograph with many different colours in each row (ABCDEABCDE...). Each value gets a (1, value) pair, which uses more space than the original.

Dictionary-Based Compression

Other lossless algorithms (like LZW, used in GIF and ZIP) build a dictionary of repeated patterns in the data and replace each occurrence with a shorter code. The decompressor uses the same dictionary to reconstruct the original.

Lossless File Formats

FormatTypeNotes
PNGImageLossless; best for screenshots, logos, diagrams with flat colours
GIFImageLossless LZW; limited to 256 colours; supports animation
BMPImageUsually uncompressed (raw bitmap)
FLACAudioLossless audio; exact original waveform preserved
ZIP / RARArchiveGeneral-purpose lossless compression for any files

Calculating Compression Ratio

Compression ratio = original size ÷ compressed size. A ratio of 4:1 means the compressed file is four times smaller than the original.

Space saving % = (1 − compressed size / original size) × 100%

Exam tip: In an RLE question, count the pairs in the encoded output. A run of 5 identical values is stored as (5, value) — two values — vs 5 values uncompressed. RLE is ineffective or harmful if there are no repeated runs.
⚠️ Common Mistakes
  • Saying lossless compression "removes" data — it does not; the original can be perfectly restored
  • Thinking RLE always reduces file size — for varied data it can increase it
  • Confusing RLE encoding (compression) with decoding (decompression)
  • Forgetting that lossy and lossless are different — this lesson covers lossless only
Video coming soon

Key points

  • Lossless compression: file size reduced but original data perfectly recoverable
  • RLE replaces runs of repeated values with (count, value) pairs
  • RLE works well on images with large solid-colour areas; poorly on photos
  • Lossless formats include PNG, FLAC, ZIP
  • Lossless is used when exact data must be preserved (programs, text, medical)
Click slide or press arrow keys to navigate
✍️

Worksheet — 3.3.8a Lossless Compression

8 questions · 16 marks

Q1What is lossless compression and what is its key advantage over lossy compression?[2]
✅ Mark scheme
Mark scheme
Lossless compression reduces file size without removing any data [1]; the original file can be perfectly reconstructed from the compressed version [1].
Q2Apply RLE to the following sequence and state the compressed output: BBBBWWWWWWBBWW[2]
✅ Mark scheme
Mark scheme
Correct encoding: 4B 6W 2B 2W [2] (or equivalent notation, e.g. (4,B)(6,W)(2,B)(2,W)) [allow 1 mark for correct method with minor error].
Q3Decode this RLE sequence: 5R 3G 2B 1Y[1]
✅ Mark scheme
Mark scheme
RRRRRGGGBBY [1] (5 R's, then 3 G's, then 2 B's, then 1 Y).
Q4Explain why RLE is more effective for a logo image than for a photograph.[2]
✅ Mark scheme
Mark scheme
A logo typically has large areas of the same colour [1]; these long runs are encoded efficiently as a single count-value pair, giving high compression ratios. A photograph has many different colours in each row, so runs are short/absent and RLE gives little or no compression (may even increase file size) [1].
Q5An original uncompressed file is 480 KB. After lossless compression it is 120 KB. Calculate the compression ratio.[2]
✅ Mark scheme
Mark scheme
480 ÷ 120 = 4 [1]; compression ratio = 4:1 [1].
Q6Give two situations where lossless compression must be used instead of lossy compression.[2]
✅ Mark scheme
Mark scheme
Any two: executable programs/software [1]; text documents / source code [1]; medical images (e.g. X-rays) where data loss could be dangerous [1]; archiving data that must be fully restored [1].
Q7Name two file formats that use lossless compression for images.[2]
✅ Mark scheme
Mark scheme
PNG [1]; GIF [1].
Q8Applying RLE to the data ABCABCABCABC would actually INCREASE the file size. Explain why.[3]
✅ Mark scheme
Mark scheme
RLE only compresses runs of the same value [1]; in ABCABCABCABC, no two consecutive values are the same [1]; RLE would produce 1A1B1C1A1B1C... — each value becomes 2 items (count+value) instead of 1, doubling the size [1].
Check your answers above.
Topic Quiz
Q 1 of 10
You scored
out of 10
Card 1 of 5
Click to flip
🎉
All done!
TermDefinition
🎯

Mini Test — 3.3.8a Lossless Compression

Timed exam conditions.

  • 8 questions · 10 minutes
  • 5 MCQ + 3 short answer
← 3.3.7 Representing Sound
31 of 57 · AQA 8525
3.3.8b Lossy Compression →