Skip to content
Cambridge AS & A Level9618

Compression

Computer Science 9618 Chapter Notes

Last updated November 2026

ShareWhatsAppPost

Compression notes as a printable PDF.

Read online free. Download a watermarked copy with a free account.

Read the notes

The full Compression notes as text: skim, search, and jump between subtopics.

~13 min read

1. Why files are compressed

Compression reduces the size of a file. A smaller file needs less storage space and less bandwidth when it is sent.

The total time taken to transmit a compressed file is shorter. Many email accounts also set a maximum size for an attachment, and a smaller file keeps within the limit.

Examiner insight

“Some candidates need to be careful when describing a reduced transmission time so that it is clear that it is the total time taken that is reduced and not the speed of data transmission.” “Some candidates found it more challenging to give either a third benefit or to expand on one of their other answers to gain the final mark.”

Worked example 12 marks

Explain why a bitmap image is often compressed before it is attached to an email.

  1. 1

    Reduced bandwidth usage when transmitting the message [1]

  2. 2

    Email accounts often have a maximum size for an attachment [1]

2. Lossy and lossless compression

With lossy compression, data is permanently lost, so the original cannot be re-created. With lossless compression, no data is lost.

Choose the method for the situation. Lossy reduces the file size more than lossless, so the file takes less storage, uses less bandwidth and is faster to upload or download. Lossless suits a situation where viewers do not want any loss of quality, or where the reduction in file size it gives is sufficient for the receiving device.

A justification says why the method suits the situation. It does not say how the method works.

Examiner insight

“Candidates were expected to state why a particular method would be chosen not how the chosen method works.” “Answers about reducing the download time were not applicable to this scenario; the duration of the streaming would be the duration of the concert.”

Worked example 13 marks

A real-time video of a music concert needs to be streamed to subscribers. Identify the most appropriate type of compression (lossy or lossless) and justify your answer.

  1. 1

    Type of compression: lossy

  2. 2

    Loss of quality will not be noticed [1]

  3. 3

    Needs to be viewed in real time, so less bandwidth is needed if the file size is smaller [1]

  4. 4

    Smaller file sizes reduce buffering, so the video plays more smoothly [1]

3. Run-length encoding of a bitmap image

Run-length encoding (RLE) is a lossless method. It finds consecutive pixels of the same colour and stores the colour and the number of times it repeats.

In the papers each run is written as the count followed by the colour. The run `1EA` is one pixel of colour `EA`. The run `3F2` is three pixels of colour `F2`.

Examiner insight

“It was not unusual to see only one FF in the second answer and 80 instead of 180 in the third answer.” “Descriptions of RLE did not always make it clear that the identical pixels were adjacent to each other.”

Worked example 12 marks

A second bitmap image is stored using a colour depth of 8 bits per pixel. The file is compressed using run-length encoding (RLE). The table shows the compressed and uncompressed values for parts of the image file. Each colour of the pixel in the image is represented by a hexadecimal value. Complete the table. The first row has been completed for you.

Uncompressed imageRLE compressed image
EA F1 F1 F2 F2 F2 EA1EA 2F1 3F2 1EA
2AB 2FF 11D 167
32 32 80 81 81
  1. 1

    Second row: `AB AB FF FF 1D 67` [1]

  2. 2

    Third row: `232 180 281` [1]

4. When RLE does not shrink an image

RLE only helps where the same colour repeats in sequence. Every run needs its colour and its count, so an image with few repeats can come out larger than before.

A row of pixels red, green, blue becomes red 1, green 1, blue 1. The data has grown, not shrunk.

Examiner insight

“The question explicitly referred to a bitmap image but some candidates incorrectly described the compression of a text file and gave an example using characters instead of colours.”

Worked example 13 marks

An image can be compressed using run-length encoding (RLE). Explain the reasons why RLE may not reduce the file size of a bitmap image. Give one example in your answer.

  1. 1

    An image may not have many sequences of the same colour [1]

  2. 2

    It would need to store each colour and then the count, which adds data [1]

  3. 3

    Example: Red-Green-Blue would become Red 1 Green 1 Blue 1 [1]

5. Lossy methods for bitmaps, and vector graphics

A bitmap can be compressed with loss by reducing the bit depth, by reducing the colour palette (fewer colours) or by reducing the image resolution. Each stores less binary for the image, and the lost detail cannot be recovered.

A vector graphic stores only the instructions to create its shapes, so its file is small already. It has little redundant data and does not compress well.

Worked example 14 marks

Riya takes a photograph using a digital camera. The photograph is stored as a bitmap image. She compresses the photograph before sending it using an email. Describe two lossy methods that Riya can use to compress the image.

  1. 1

    Method 1: reduce the bit depth [1]

  2. 2

    ...which means each pixel has fewer bits [1]

  3. 3

    Method 2: reduce the image resolution [1]

  4. 4

    ...fewer pixels per unit measurement means less binary to store [1]

6. Compressing a text file

A text file needs lossless compression. All the data is required, so no data can be lost. Otherwise the text file is corrupted and does not make sense.

RLE works on text too. Repeated sequences of the same characters are replaced by a single copy of the character and a count of how many there were.

Examiner insight

“A small number of candidates wrote about images and pixels rather than text files and characters.”

Worked example 12 marks

RLE is an example of lossless compression. Explain why lossless compression is more appropriate than lossy compression for a text file.

  1. 1

    All the data is required, so no data can be lost [1]

  2. 2

    Otherwise the text file will be corrupted and not make sense [1]

7. Compressing a sound file

Lowering the sampling rate is lossy. There are fewer samples per second, so data is permanently lost and the original sound cannot be re-created.

A lossless method is RLE. Where consecutive sounds are the same, record the binary value of the sound and the number of times it repeats. Another is to record the changes instead of the actual sounds.

Worked example 12 marks

Bobby is recording a sound file for his school project. He compresses the file before sending the email. Bobby uses lossless compression. Describe how lossless compression can compress the sound file.

  1. 1

    Run-length encoding: where consecutive sounds are the same, record the binary value of the sound and the number of times it repeats [1]

  2. 2

    Or record the changes instead of the actual sounds [1]

Recap

  • Compression reduces file size: less storage, less bandwidth, a shorter total transmission time, and files within an attachment limit.
  • Lossy: data is permanently lost and the original cannot be re-created. Lossless: no data is lost.
  • Justify a choice by why it suits the situation, not by how the method works.
  • RLE stores the colour and the number of times it repeats. It only helps when pixels of the same colour are consecutive.
  • Lossy bitmap methods: reduce bit depth, colour palette or image resolution.
  • A text file needs lossless compression: no data can be lost or it is corrupted.
  • Sound: a lower sampling rate is lossy. RLE or recording the changes is lossless.

End-of-chapter exercise

Test yourself on the whole chapter. Work through these before moving on.

  1. A student compresses a photograph before emailing it. Give one reason, referring to time.1 mark
    Answer
    1. The total time taken to send the file is reduced because the file is smaller [1].

    Trap: Examiners reported answers that said the speed of transmission increases. The speed is unchanged; the time falls.

  2. State what happens to the data in lossy compression and in lossless compression.2 marks
    Answer
    1. Lossy: data is permanently lost, so the original cannot be re-created [1].
    2. Lossless: no data is lost [1].

    Trap: The two terms are easy to swap. Lossless means nothing is lost.

  3. A photograph is to be compressed with a lossy method. State two changes that reduce its file size.2 marks
    Answer
    1. Reduce the bit depth (fewer bits per pixel) [1].
    2. Reduce the image resolution (fewer pixels) [1].

    Trap: Run-length encoding is lossless. Screen resolution is not image resolution, and changing it does not change the file.

  4. A row of 12 pixels is `R R R R G G B B B B B B`, where each letter is a colour. Write it using run-length encoding, as a count followed by a colour for each run.2 marks
    Answer
    1. The runs are 4 red, 2 green and 6 blue [1].
    2. `4R 2G 6B` [1]. Check: 4 + 2 + 6 = 12 pixels.

    Trap: Counting the runs instead of the pixels in each run, or leaving out the last run.

  5. A bitmap image uses two-digit hexadecimal colour values. A row is stored with RLE as `3F0 1A2 2FF`, a count followed by a colour. Write the uncompressed row.2 marks
    Answer
    1. Each run is a one-digit count then a two-digit colour: 3 of `F0`, 1 of `A2`, 2 of `FF` [1].
    2. `F0 F0 F0 A2 FF FF` [1].

    Trap: Reading `3F0` as the colour `3F` followed by 0. The count is the first digit only.

  6. A row of 8 pixels alternates black and white: `B W B W B W B W`. Write it using run-length encoding, as a count followed by a colour. Count each count and each colour as one item. Compare the number of items before and after.3 marks
    Answer
    1. Every run is one pixel long: `1B 1W 1B 1W 1B 1W 1B 1W` [1].
    2. Before: 8 items. After: 8 runs of 2 items, which is 16 items [1].
    3. RLE has made the data larger because no pixels of the same colour are consecutive [1].

    Trap: Assuming RLE always shrinks the data.

  7. A solicitor emails a contract saved as a text file. A colleague suggests lossy compression to make the file smaller. Explain why this is unsuitable.3 marks
    Answer
    1. Lossy compression permanently loses data [1].
    2. All the data in a text file is required, so no data can be lost [1].
    3. Otherwise the text would be corrupted and would not make sense [1].

    Trap: Explaining the benefit of a smaller file. The question asks why lossy fails for this file.

  8. A sound file is compressed by lowering its sampling rate. State whether this is lossy or lossless and justify your answer. Then describe one lossless method for the sound file.3 marks
    Answer
    1. Lossy [1].
    2. There are fewer samples per second, so data is permanently lost and the original sound cannot be re-created [1].
    3. Lossless: RLE, recording the binary value of consecutive identical sounds and the number of times it repeats [1].

    Trap: Calling it lossless because the sound still plays. The test is whether the original can be re-created.

  9. A bitmap image has a colour depth of 8 bits per pixel. Each colour is a two-digit hexadecimal value. The image is compressed with RLE, each run written as a count followed by the colour, as in `3F2`. In the compressed file each count is stored in 8 bits, the same as a colour. (a) Compress row A: `C4 C4 C4 07 07 C4 C4 C4 C4 07 9B 9B`. [2] (b) Calculate the size of row A in bytes before and after compression. [2] (c) Row B is `07 C4 07 C4 07 C4 9B 9B`. Calculate its size in bytes after compression and explain the result. [2]6 marks
    Answer
    1. (a)
    2. Runs of adjacent pixels: 3 of `C4`, 2 of `07`, 4 of `C4`, 1 of `07`, 2 of `9B` [1].
    3. `3C4 207 4C4 107 29B` [1]. Check: 3 + 2 + 4 + 1 + 2 = 12 pixels.
    4. (b)
    5. Before: 12 pixels of 8 bits each, which is 12 bytes [1].
    6. After: 5 runs of 2 bytes (count and colour), which is 10 bytes [1].
    7. (c)
    8. `107 1C4 107 1C4 107 1C4 29B` is 7 runs of 2 bytes, which is 14 bytes, more than the 8 bytes before [1].
    9. There are few consecutive pixels of the same colour, and each run stores a count as well as the colour, which adds data [1].

    Trap: Writing a single pixel without its count of 1, as examiners saw with 80 for 180, or joining `C4` pixels that are not adjacent into one run.

  10. A wildlife charity sends three files from a field station over a slow satellite link. For each, state lossy or lossless and justify the choice. (a) A live video of a bird's nest, watched by the public as it happens. [3] (b) A text file of bird counts that scientists will analyse. [2] (c) A recording of bird song that researchers will compare with the original sound. [2]7 marks
    Answer
    1. (a)
    2. Lossy (no mark for the choice).
    3. Loss of quality will not be noticed by the viewers [1].
    4. It is viewed in real time, so less bandwidth is needed if the file size is smaller [1].
    5. Smaller file sizes reduce buffering, so the video plays more smoothly [1].
    6. (b)
    7. Lossless.
    8. All the data is required, so no data can be lost [1].
    9. Otherwise the text file is corrupted and does not make sense [1].
    10. (c)
    11. Lossless.
    12. The researchers do not want any loss of quality [1].
    13. Lossy compression permanently loses data, so the original sound could not be re-created [1].

    Trap: Justifying the live video by a shorter download time. Examiners rejected this: a live stream lasts as long as the event, and a justification says why, not how.

Say this, not that

Wording that loses the mark, against the wording the mark scheme credits.

Loses the markGets the mark
RLE looks for repeated characters in the image.RLE replaces consecutive pixels of the same colour with the colour and the number of times it repeats.
Compression makes the data transmit faster.Compression reduces the total time taken to transmit the file. The speed does not change.
Lossy compression suits the live stream because it reduces the download time.Loss of quality will not be noticed, and less bandwidth is needed in real time.
RLE always makes the file smaller.RLE may not reduce the size if the image has few sequences of the same colour.

Frequently asked questions

Why are files compressed before they are sent by email?
Compression makes a file smaller, so it needs less storage space and less bandwidth to send. The total time taken to transmit it is shorter, although the speed of transmission does not change. Many email accounts also set a maximum size for an attachment, and a smaller file keeps within that limit.
What is the difference between lossy and lossless compression?
With lossy compression data is permanently lost, so the original cannot be re-created. With lossless compression no data is lost. Lossy reduces the file size more, so it suits a case where the loss of quality will not be noticed. Lossless suits viewers who do not want any loss of quality.
How does run-length encoding (RLE) compress a bitmap image?
RLE is a lossless method. It finds consecutive pixels of the same colour and stores the colour and the number of times it repeats. A run written as 3F2 means three pixels of colour F2. It only helps where the same colour repeats in sequence.
Why does run-length encoding sometimes make an image file bigger?
RLE only helps where the same colour repeats in sequence. Each run needs its colour and its count, so an image with few repeats can come out larger than before. For example, red, green, blue becomes red 1, green 1, blue 1. Assuming that RLE always makes the file smaller is a common mistake.
Why must a text file be compressed with lossless compression?
All the data in a text file is required, so no data can be lost. If any data is lost by lossy compression, the text file is corrupted and does not make sense. RLE is a lossless method that also works on text, replacing repeated characters with a single copy and a count.
How can a bitmap image be compressed using a lossy method?
Reduce the bit depth, so each pixel has fewer bits, reduce the colour palette, or reduce the image resolution, which means fewer pixels per unit measurement. Each one stores less binary, and the lost detail cannot be recovered. A vector graphic stores only instructions, so it does not compress well.

Free notes are just the start.

Unlock every Workbook and Chapter at a Glance, and generate your own worksheets and predicted papers.

Explore plans

Related chapters