Lossy and lossless compression
Choose a compression method by weighing file size, recoverability, media type and intended use.
Mapped to the Cambridge IGCSE Computer Science 0265 syllabus for exams in 2029. These original explanations and self-checks are independent study support, not Cambridge papers, official marks or grades. Practical programming is taught with worked code and trace tasks; an executable Python workspace and timed digital-exam simulation are not yet available.
Before you begin
- Use the 2029 syllabus for this course. Cambridge specifies Python 3.10 or higher for programming and digital exams for both components. The syllabus currently identifies this route for 2029 only; confirm later-year availability with Cambridge and your school.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
Before lossy and lossless compression, which statement is the safest starting point?
What you will learn
- Explain why data is compressed for storage or transmission
- Describe lossy compression and RLE/Huffman lossless compression
- Select and justify a method for a scenario
Compression trades size against other properties
Compression reduces the number of bits needed to store or transmit data. Smaller files can save storage and reduce transmission time, but the method may need processing and can affect quality or recoverability.
Lossy compression discards some information. It can produce much smaller image, sound or video files when a small quality loss is acceptable, but the exact original cannot be reconstructed from the compressed data.
Lossless methods preserve the original
Run-length encoding (RLE) stores repeated values as a value and a count. It works well for long runs of the same value but can make data larger when repetition is rare. Huffman coding uses shorter codes for frequent symbols and longer codes for less frequent symbols; learners need to explain its effect, not create or interpret a Huffman tree.
Lossless methods reconstruct the exact original, which matters for text and data where a changed symbol could alter meaning. Compare the expected size reduction and the consequences of lost information before choosing.
Pause and explain
Which habit best checks your understanding of lossy and lossless compression?
Worked example
A medical text record must be stored compactly without changing any character. Recommend a method and explain why.
Show the worked solution
- The text must be recovered exactly.
- Lossy compression could remove information and is unsuitable.
- A lossless method such as Huffman coding can reduce size while preserving the original.
Answer Use lossless compression; it preserves every character when decompressed.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Encode the string AAAABBCCC as simple value-count pairs. State why RLE suits this example.
Give me a hint
Group each consecutive run and count its length.
Compare my reasoning
- A appears four times in one run.
- B appears twice.
- C appears three times.
A4 B2 C3; the repeated runs are compactly represented.
Look for these in your work
- Runs identified
- Counts correct
- Suitability explained
A photograph will be sent over a slow connection and a small visible quality loss is acceptable. Choose a compression type and justify it.
Give me a hint
Consider the media type, transmission need and whether exact recovery is required.
Compare my reasoning
- The photo is an image and the goal is to reduce transmission size.
- Lossy compression can discard less noticeable detail for a smaller file.
- State the trade-off: the original image cannot be reconstructed exactly.
Lossy image compression is suitable if the quality loss is acceptable.
Look for these in your work
- Goal identified
- Method matched
- Trade-off stated
A text archive contains many long repeated characters and must be restored exactly. Compare RLE and lossy compression for this use.
Give me a hint
Preserve exact characters, then examine whether runs make RLE useful.
Compare my reasoning
- Exact recovery rules out lossy compression.
- Long repeated runs give RLE opportunities to store a count instead of each character.
- The archive should be checked for actual size reduction, since RLE is not beneficial for every pattern.
Use a lossless method; RLE is promising for the repeated runs, but verify the resulting size.
Look for these in your work
- Exactness considered
- Run pattern assessed
- Limit acknowledged
Common mistakes
- Claiming a lossy file can be restored exactly.
- Assuming RLE always reduces file size.
- Choosing a method without considering the file type and purpose.
What can you explain now?
Is RLE guaranteed to make every file smaller?
Compare with the explanation
No
Files with few repeated runs may need more storage after run counts are added.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
When would lossy compression be acceptable, and how do RLE and Huffman coding differ from it?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.