📦 Component 1 · 1.2 Data Representation
1.2.5 Compression (Lossy, Lossless & Run-Length Encoding)
OCR J277 · GCSE Computer Science · ~13 min read
Notes
Video
Slides
Worksheet
Quiz

Why Compress Files?

Digital files — especially images, audio, and video — can be very large. Compression reduces file size so that:

  • Files take up less storage space (hard drives, memory cards)
  • Files can be transmitted faster over a network (smaller = quicker to download/upload)
  • More files can be stored on a device

There are two main types of compression: lossy and lossless.

Lossy Compression

Lossy compression permanently removes data that is considered less important or less perceptible to humans. The original file cannot be perfectly reconstructed from the compressed version.

PropertyDetail
Data removedYes — permanently discarded
Reversible?No — original cannot be recovered
File size reductionLarge — can reduce by 90%+
QualityReduced — some detail lost
File examplesJPEG (images), MP3 (audio), MP4/MPEG (video)

How it works (JPEG example): removes colour information from areas where the eye is less sensitive to detail — e.g. gradients in skies are simplified. Small details and colour variations humans can barely see are removed, reducing file size greatly.

How it works (MP3 example): removes audio frequencies that are masked by louder sounds or are too high/low for most people to hear clearly.

Lossless Compression

Lossless compression reduces file size without losing any data. The original file can be perfectly reconstructed from the compressed version. It works by finding patterns and redundancy in data and encoding them more efficiently.

PropertyDetail
Data removedNo — all data preserved
Reversible?Yes — original perfectly restored on decompression
File size reductionModerate — less reduction than lossy
QualityPerfect — no quality loss
File examplesPNG (images), FLAC (audio), ZIP/RAR (archives)

Comparing Lossy and Lossless

FactorLossyLossless
Quality after compressionReduced (data lost)Perfect (no data lost)
File size reductionLarger reductionSmaller reduction
Can reconstruct original?NoYes
Best forPhotos, music, video streamingText, programs, medical images
ExamplesJPEG, MP3, MP4PNG, FLAC, ZIP

Run-Length Encoding (RLE)

Run-length encoding is a simple lossless compression algorithm. It replaces consecutive runs of the same value with a (count, value) pair. It works best when there are long sequences of repeated values — common in images with large areas of the same colour.

RLE Example — Pixel colours

Original: R R R R R B B B B G G R R R R R R R
Encoded: 5R 4B 2G 7R
Original: 18 values    Compressed: 4 pairs (8 values) → saves ~56%

RLE Example — Binary image

Original: 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0
Encoded: (6,0) (3,1) (7,0)
Original: 16 bits    Compressed: 3 pairs → stores in far fewer bits

Limitation: RLE performs poorly on data with very few repeated values (e.g. a photograph with many different colours). In the worst case, it can make the file larger.

Where RLE works well: simple graphics, icons, black-and-white images, fax transmissions.

Exam tip: Know the difference between lossy and lossless — quality, reversibility, file size reduction, and examples. Know when to use each: medical images and executable programs must use lossless (data loss unacceptable); photos and music for streaming often use lossy (some quality loss acceptable). Be able to apply RLE to a simple sequence and calculate savings. OCR often asks for lossy/lossless advantages and disadvantages.
⚠️ Common Mistakes
  • Saying lossless "loses some data" — it does NOT. Lossless = no data is ever lost
  • Confusing JPEG (lossy) with PNG (lossless) — JPEG loses data, PNG does not
  • Saying lossy is "always worse" — for streaming music/video, lossy is the standard because quality loss is unnoticeable and file size savings are huge
  • Applying RLE to data that has few repeated values and then saying it always saves space — RLE can increase file size on random data
  • Forgetting that ZIP is lossless — it perfectly reconstructs the original file
✅ Notes completed!
Video coming soon

What's in this video

  • • Why compression is needed: storage and transmission
  • • Lossy compression: data permanently removed, JPEG, MP3
  • • Lossless compression: all data preserved, PNG, ZIP
  • • Run-length encoding: how it works, worked examples, limitations
Click slide or press arrow keys to navigate

Worksheet — 1.2.5 Compression

8 questions · 20 marks

Q1State two reasons why files are compressed.[2]
✅ Mark scheme
Reduces file size → less storage space needed [1]; smaller files transmit faster over networks / quicker to upload or download [1].
Q2Explain the difference between lossy and lossless compression.[4]
✅ Mark scheme
Lossy: permanently removes some data from the file [1]; the original cannot be perfectly restored [1]. Lossless: reduces file size without removing any data [1]; the original file can be perfectly restored upon decompression [1].
Q3Give one example each of a lossy and a lossless file format.[2]
✅ Mark scheme
Lossy: JPEG / MP3 / MP4 [1]; Lossless: PNG / FLAC / ZIP [1].
Q4Explain how run-length encoding (RLE) works. Use an example.[3]
✅ Mark scheme
RLE replaces consecutive repeated values with a (count, value) pair [1]; e.g. R R R R B B → 4R 2B [1]; reduces data when there are many repeated values [1].
Q5Apply RLE to the following sequence: W W W W W W B B W W W W B B B B W W
How many values are in the original vs compressed?
[3]
✅ Mark scheme
RLE: 6W 2B 4W 4B 2W [1]; Original: 18 values [1]; Compressed: 5 pairs (10 values) [1].
Q6A medical image must be compressed. Explain why lossless compression must be used rather than lossy.[2]
✅ Mark scheme
Lossy compression permanently removes data [1]; in a medical image, removed data could be important diagnostic information — a misdiagnosis could result from missing detail [1].
Q7State one advantage and one disadvantage of lossy compression.[2]
✅ Mark scheme
Advantage: much smaller file size — greater reduction than lossless [1]; Disadvantage: quality is permanently reduced / original cannot be restored [1].
Q8State one situation where RLE is effective and one where it is not. Explain why in each case.[2]
✅ Mark scheme
Effective: simple graphics / cartoon images with large areas of the same colour — many repeated values → good compression [1]; Not effective: detailed photographs — few repeated consecutive values, encoding each with (1,value) could increase file size [1].
?
out of 20 — self-mark above
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 15
Click to reveal definition
🎉
Complete!
TermDefinition
🎯

Mini Test — 1.2.5 Compression

10 questions · 10 marks · 10 minutes

← 1.2.4g Representing Sound 1.2 Data Representation 1.3.1a Networks →
🔒
Unlock Everything
Subscribe to access all OCR J277 lessons.
£7.99/month
or £59/year
Subscribe now →