Data storage and compression

Computer Science · Data representation. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science topics

The idea

The smallest unit of data is the bit, a single 1 or 0. Larger units are built up in steps of 1024, because 1024 is 210.

You can work out a file size from what the file holds. An image stores one colour code for every pixel. A sound file stores one value for every sample. Find the size in bits first, then divide to change the unit.

Compression makes a file smaller so it needs less storage, less bandwidth and less time to send. Lossy compression removes data for ever. Lossless compression loses nothing, so the original file can be rebuilt exactly.

In simpler words

A bit is a single 1 or 0. Eight bits make a byte. Bigger units go up in steps of 1024. To find a picture's file size, multiply width by height by bits per pixel. For sound, multiply samples per second by bits per sample by seconds. Compression makes files smaller. Lossy removes data for ever. Lossless keeps everything so the file can be rebuilt.

An everyday comparison

Lossy compression is like summarising a book: shorter, but some details are gone for ever. Lossless compression is like vacuum-packing clothes: smaller to carry, but every item comes out exactly as it went in. Run length encoding is like writing '10 red' instead of 'red' ten times. The comparison stops working because lossy files often keep details people barely notice, like quiet sounds in music.

Rules to remember

Common mistake

Students forget to divide by 8 and give the answer in bits when the question asks for bytes. Always check which unit is asked for.

In the exam

Write the formula first: image size = width × height × colour depth. Substitute the numbers to get bits. Then divide by 8 for bytes, by 1024 for KiB, and by 1024 again for MiB, showing each step. Give the answer in the unit asked. For compression, name lossy or lossless, give an example such as JPEG or RLE, and say why it suits that file type.

Worked example

An image is 2048 pixels wide and 1024 pixels high with a colour depth of 24 bits. What is its file size in MiB?

  1. Size in bits = 2048 × 1024 × 24 = 50 331 648 bits.
  2. Bytes = 50 331 648 ÷ 8 = 6 291 456 bytes.
  3. KiB = 6 291 456 ÷ 1024 = 6144 KiB.
  4. MiB = 6144 ÷ 1024 = 6 MiB.

Answer: The file size is 6 MiB.

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

← Text, sound and imagesTypes and methods of data transmission →Take a Computer Science test