GCSE · Computer Science · OCR · Spec J277
Lossless compression
Shrink a file, then get every single bit of it back. Sounds like cheating? That's lossless compression.
Do the round trip
Compress it, decompress it, compare it
One tiny text file goes there and back twice: once with lossless compression, once with lossy. The question is always the same: did it all come back?
Before each Next, predict what the next line will leave behind.
1 original = "Do not touch the wire"2 packed = losslessCompress(original)3 restored = decompress(packed)4 print(restored)5 if restored == original then6 print("Identical")7 endif8 squashed = lossyCompress(original)9 approx = decompress(squashed)10 print(approx)11 if approx == original then12 print("Identical")13 else14 print("Only an approximation")15 endif
Variables
Output
Step 1: Here's a tiny text file. The job: make it smaller, then get it back. Will every letter survive? Hold that thought.
Press Next to run one line at a time. This is a walk-through: the page shows each state, but it doesn't compress anything itself.
Which method would you pick?
Sort the files
Which kind of compression suits each file?
Still to sort
Lossless (0)
No data is permanently lost, and the original comes back exactly.
Where the line is: Choose it when accuracy and detail are important, or when no letters or words can be lost.
Lossy (0)
Data is permanently deleted, so only an approximation comes back.
Where the line is: Only where some quality loss is acceptable and a smaller file matters more.
Pick a file, then drop it on the method that suits it. Read why each one lands where it does.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Make a file smaller, then get the original back exactly. And when that matters.
What you need to know
- Compression makes a file smaller, by removing unnecessary data or rearranging information more efficiently.
- Smaller files need less storage space, locally or in the cloud, use less bandwidth, and upload and download faster.
- You can't use a compressed file as it is. It must be decompressed, and a decompression algorithm recreates a version of it.
Have a goYour mate insists a compressed file needs no decompressing, 'because it's already a file'. What have they missed?
It must be decompressed before it can be used.
A decompression algorithm is what recreates a version of the file, so being a file isn't enough on its own.
- There are two categories of compression algorithm: lossless and lossy.
- Lossless compression loses no data permanently, so it shrinks the file without losing any data.
Have a goDev says: 'Making a file smaller always means throwing something away.' Does that hold for lossless compression?
No. Lossless shrinks the file without losing any data.
Dev is describing lossy compression. Lossless means no data is permanently lost, even though the file gets smaller.
- So a lossless file can be restored to the original version, because none of the data gets removed.
- Lossy compression permanently deletes data, so the decompressed file is only an approximation, never an exact copy.
- Use lossless when accuracy and detail matter. Text files need it, so no letters or words are lost.
Have a goYour cousin wants their essay smaller and says: 'Just use a method that deletes some data, nobody will notice.' What do you tell them?
Use lossless. It's a text file, so no letters or words can be lost.
Deleting data is permanent, and with text even one missing word could change what it says.
- PNG is a common lossless file type, used with images that must keep the highest quality during transfer.
- Choosing a method depends on the need for accuracy, the acceptable quality loss, and how much a smaller file matters.
The big picture
Data compression reduces the size of a file, by removing unnecessary data or rearranging information more efficiently. That saves storage space, uses less bandwidth and speeds up uploading and downloading, but a compressed file must be decompressed before it is used. The two categories are lossless and lossy. Lossless compression loses no data permanently, so the original can be restored exactly, and it is used when accuracy and detail are important, such as text files and PNG images. Lossy compression permanently deletes data, so decompressing gives only an approximation. The choice depends on the need for accuracy, the acceptable quality loss and the importance of a smaller file.
Key points
Worked example
Problem
A club secretary must email two files over a slow connection: the minutes of a meeting (a text file) and a team photo where a close copy would be fine. Which kind of compression suits each file, and why?
⚠ Watch out
Thinking all compression loses data. Only lossy compression permanently deletes data. Lossless compression keeps all of it, so a lossless file can be restored to the original.
Memory hook
Lossless loses nothing: you get the original back. Lossy loses some for good: you get a lookalike.
Check yourself
Cover the page. Say what happens to a text file that goes through lossless compression and then decompression, and why a method that permanently deletes data would be a problem for it.
Flashcards
(12)What is data compression?
Three advantages of compressing a file?
Why must a compressed file be decompressed?
What are the two categories of compression algorithm?
What is lossless compression?
Can a losslessly compressed file be restored to the original? Why?
When is lossless compression used?
Why do text files need lossless compression?
What is PNG?
You decompress a lossy file. Is it an exact copy of the original?
What three things does the choice of compression method depend on?
One quick test to tell lossless from lossy?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore OCR GCSE Computer Science topics
How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 14 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.