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 then
6 print("Identical")
7 endif
8 squashed = lossyCompress(original)
9 approx = decompress(squashed)
10 print(approx)
11 if approx == original then
12 print("Identical")
13 else
14 print("Only an approximation")
15 endif

Variables

original=Do not touch the wire

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.

1 / 11

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.

Step 1 of 11: Here's a tiny text file. The job: make it smaller, then get it back. Will every letter survive? Hold that thought..

Which idea do you hold?

Dev's compressed essay

Dev compresses a typed essay, a text file, using a lossless method and sends it to a friend, Ana. Ana gets the compressed file.

What is true about Ana's file? Pick the idea closest to what you think, then say how sure you are.
How sure are you?

Two categories, one big question

LosslessvsLossy

Both make files smaller. What happens to the data is where they split.

Focus

What happens to the data

Lossless

No data is permanently lost

Lossy

Data is permanently deleted

The insight

Everything else on this page follows from this one difference.

File size

Lossless

Reduced without losing any data

Lossy

Reduced by deleting data

After decompressing

Lossless

Restored to the original version of the file

Lossy

Only an approximation of the original, never an exact copy

Which way the choice leans

Lossless

Accuracy and detail are important

Lossy

Some quality loss is acceptable and a smaller file matters

A text file

Lossless

Needed, so no letters or words are lost

Lossy

Not the choice, because it permanently deletes data

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.

6 of 6 still to sort.

Pick a file, then drop it on the method that suits it. Read why each one lands where it does.

Your turn to write

Why compress, and why lossless for text?

A school keeps a lot of text files. Give two advantages of compressing its files. Then explain why the text files must be compressed with lossless compression. [4 marks]

0 words · your answer stays on this page and is not sent anywhere.

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

1Data compression reduces the size of a file, by removing unnecessary data or rearranging information more efficiently.
2Smaller files save storage space, use less bandwidth and upload and download faster, but a compressed file must be decompressed before it is used.
3The two categories of compression algorithm are lossless and lossy.
4Lossless compression loses no data permanently, so the file can be restored to the original version.
5Lossy compression permanently deletes data, so the decompressed file is only an approximation of the original.
6Lossless is used when accuracy and detail are important, for example text files and PNG images; the choice depends on the need for accuracy, the acceptable quality loss and the importance of a smaller file.

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?
Reducing the size of a file, using algorithms that remove unnecessary data or rearrange information more efficiently.
Three advantages of compressing a file?
Less storage space (locally or in the cloud), less bandwidth when sending it on a network, and faster uploading and downloading.
Why must a compressed file be decompressed?
It has to be decompressed to be accessed or used. A decompression algorithm recreates a version of the file.
What are the two categories of compression algorithm?
Lossless and lossy.
What is lossless compression?
A method where no data is permanently lost, so the file gets smaller without losing any data.
Can a losslessly compressed file be restored to the original? Why?
Yes. None of the data gets removed during compression, so the original version can be restored.
When is lossless compression used?
When accuracy and detail are important.
Why do text files need lossless compression?
It's important that no letters or words are lost during compression.
What is PNG?
A common lossless compression file type, used with images that must retain the highest quality during transfer.
You decompress a lossy file. Is it an exact copy of the original?
No. Lossy compression permanently deletes data, so you only get an approximation.
What three things does the choice of compression method depend on?
The need for data accuracy, the acceptable level of quality loss, and the importance of reducing file size.
One quick test to tell lossless from lossy?
Can you get the original back exactly after decompressing? If yes, it was lossless.

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 posted

More OCR GCSE Computer Science topics

See the full OCR Computer Science curriculum →

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.