O Level Computer Science 2210 · Area 1 · Computer systems

Data storage and compression

This page is where the arithmetic in topic 1 pays off: storage units, the 1024 multiplier, and the two file-size calculations you will be asked to perform. It also covers why compression is needed and how lossy and lossless methods differ. Marks are lost here at the last step — dividing by 1000 instead of 1024, or answering in the wrong unit — so keep the unit on every line of working.

Not started

Syllabus coverage

  • Understand how data storage is measured, including the bit, nibble, byte, kibibyte, mebibyte, gibibyte, tebibyte, pebibyte and exbibyte
  • Know how many of the previous unit are in each unit, for example 8 bits in a byte and 1024 mebibytes in a gibibyte
  • Calculate the file size of an image file from its resolution and colour depth, and of a sound file from its sample rate, sample resolution and length
  • Give answers in the units specified in the question, using 1024 and not 1000 for every step between storage units
  • Understand the purpose of and need for data compression, including the effect on bandwidth, storage space and transmission time
  • Understand how files are compressed using lossy compression, which permanently removes data, and lossless compression, which does not

Part of the O Level Computer Science syllabus 2210.

Storage units, file size and compressionEach step up from a byte is 1024 of the unit before it, never 1000.Compression shrinks a file either by losing data permanently or by storing it more efficiently.Units of storagebitone binary digitnibble4 bitsbyte8 bits = one characterkibibyte (KiB)1024 bytesx1024mebibyte (MiB)1024 KiBx1024gibibyte (GiB)1024 MiBFile size, then compressionFile size in bits= pixels x colour depth= sample rate x resolution x length in secondsbits / 8 = bytesbytes / 1024 at each step upLossy removes data permanently:it cannot be restored.Lossless stores it more efficiently:the original is restored exactly.A smaller file needs less storage.
A ladder of storage units climbing from a bit through nibble, byte, kibibyte and mebibyte to gibibyte, with the multiple of 1024 written between each pair of rungs.

The ladder of storage units

Data storage is measured in a ladder of units, and each unit is a fixed multiple of the one below it. A bit is one binary digit, either 0 or 1, and it is the smallest unit there is. A nibble is 4 bits, which is the width of one hexadecimal digit. A byte is 8 bits, which is enough for one ASCII character.

Above the byte, each step is 1024 of the previous unit. There are 1024 bytes in a kibibyte (KiB), 1024 KiB in a mebibyte (MiB), 1024 MiB in a gibibyte (GiB), 1024 GiB in a tebibyte (TiB), 1024 TiB in a pebibyte (PiB) and 1024 PiB in an exbibyte (EiB). The names look like the everyday kilo, mega and giga, but the multipliers are powers of 2 rather than powers of 10, and that difference is the whole point of the -bi- spelling.

The units are not decorative: a phone's storage is quoted in GiB, a hard disk in TiB, and a data centre in PiB or EiB. Being able to move up and down the ladder without losing a factor of 1024 is the skill this page is built on.

UnitSymbolHow many of the previous unit
Bitbone binary digit
Nibble—4 bits
ByteB8 bits, or 2 nibbles
KibibyteKiB1024 bytes
MebibyteMiB1024 KiB
GibibyteGiB1024 MiB
TebibyteTiB1024 GiB
PebibytePiB1024 TiB
ExbibyteEiB1024 PiB

Why the multiplier is 1024 and not 1000

Storage is addressed in binary, so the natural grouping is a power of 2, and 1024 is 2 to the power 10 — the first power of two above a thousand. That is why a kibibyte is 1024 bytes and not 1000, and why the syllabus states that calculations must use 1024 and not 1000.

The everyday units kilo, mega and giga are decimal: a kilogram is 1000 grams. Manufacturers sometimes use those decimal meanings when quoting disk capacity, which is why a drive sold as 1 TB shows less than 1 TiB in an operating system that counts in powers of two. Both numbers can be defensible, but an exam answer must use 1024, because that is the convention the syllabus has fixed.

Use the symbols carefully as well. KiB means kibibyte and is a multiple of 1024; KB conventionally means kilobyte and is a multiple of 1000. If a question asks for KiB, an answer in KB is a different quantity, and the unit mark can be lost even when the arithmetic is right.

Every step up the ladder divides by 1024. Only the bit-to-byte step divides by 8, because a byte is 8 bits and not a power-of-two multiple of a thousand.

Moving up and down the ladder

To go up a unit, divide by 1024. To go down, multiply by 1024. So 3 MiB is 3 × 1024 = 3072 KiB, and 2 GiB is 2 × 1024 = 2048 MiB. The arithmetic is simple; the errors come from using 1000 or from dividing when the question needed a multiplication.

Bits and bytes sit on either side of a factor of 8, which trips up more students than anything else in this topic. One MiB is 1024 KiB, which is 1024 × 1024 = 1 048 576 bytes, which is 1 048 576 × 8 = 8 388 608 bits. A file size given in bits therefore has to be divided by 8 before any of the 1024 steps apply.

Write the chain out rather than trying to do it in one jump: bits → bytes (÷ 8) → KiB (÷ 1024) → MiB (÷ 1024). Each arrow is one mark in a typical mark scheme, and a chain also makes it obvious which unit your answer is in.

FromToOperation
BitsBytes÷ 8
BytesKiB÷ 1024
KiBMiB÷ 1024
MiBGiB÷ 1024
GiBMiB× 1024
MiBKiB× 1024

Calculating the size of an image file

The size of an uncompressed image is the number of pixels multiplied by the number of bits used for each pixel: file size in bits = resolution × colour depth, where the resolution is the total pixel count (width × height).

Worked example: an image is 512 × 512 pixels with a colour depth of 8 bits. The pixel count is 512 × 512 = 262 144. Multiply by the colour depth: 262 144 × 8 = 2 097 152 bits. Divide by 8 to get bytes: 262 144 bytes. Divide by 1024 to get KiB: 256 KiB.

A second example that crosses into mebibytes: 1024 × 512 pixels at 16 bits. Pixel count 524 288; × 16 = 8 388 608 bits; ÷ 8 = 1 048 576 bytes; ÷ 1024 = 1024 KiB; ÷ 1024 = 1 MiB. Notice that the answer only becomes sensible once the unit is right — 8 388 608 on its own tells the reader nothing about whether the file will fit on a device.

The formula assumes no compression, and the syllabus wording is 'using information given', so use exactly the resolution and colour depth in the question even if they look unusual. Do not silently assume 24-bit colour.

Image file size in bits = width × height × colour depth. Then ÷ 8 for bytes and ÷ 1024 for each step up.

Calculating the size of a sound file

An uncompressed sound file is the sample rate multiplied by the sample resolution multiplied by the length of the recording in seconds: file size in bits = sample rate × sample resolution × length. The sample rate is in samples per second, so multiplying by the length in seconds gives the total number of samples.

Worked example: a recording is made at 8192 samples per second with a sample resolution of 16 bits and a length of 4 seconds. The number of samples is 8192 × 4 = 32 768. Multiply by 16 bits per sample: 524 288 bits. Divide by 8: 65 536 bytes. Divide by 1024: 64 KiB.

The commonest error is to leave out the length, which gives the size of one second of audio rather than the size of the track. The second commonest is to use the length in minutes without converting to seconds, which is out by a factor of 60. The syllabus gives the length in seconds, but check anyway.

As with images, the answer is uncompressed. A real music file is smaller than this calculation suggests because it has been compressed, which is the subject of the rest of this page.

Getting the final answer into the right unit

File-size questions usually specify the unit, and the unit is worth a mark. If the question asks for KiB, stop dividing when you reach KiB; if it asks for MiB, take one more step. Converting past the requested unit and giving a decimal is a needless risk.

When the numbers do not divide exactly, give the answer to a sensible number of decimal places and keep the unit. A 3-second recording at 44100 samples per second and 16 bits is 2 116 800 bits, which is 264 600 bytes, which is about 258.4 KiB. Quoting 258.4 KiB is correct; quoting 258 398.4 bytes when the question asked for KiB is not answering the question.

Keep the unit on every line of working. It looks fussy, but it is the cheapest way to notice that you have divided by 1024 one time too few, and examiners award method marks for a chain that is right even when the final slip is arithmetic.

QuantityFormulaUnit of the result
Image sizewidth × height × colour depthbits, before conversion
Sound sizesample rate × sample resolution × length in secondsbits, before conversion
Bits to bytes÷ 8bytes
Bytes to KiB÷ 1024KiB
KiB to MiB÷ 1024MiB

Why compression is needed

Compression exists to reduce the size of a file. The need is not abstract: the same file has to be stored, moved across a network and kept for later, and every one of those is cheaper when the file is smaller.

The syllabus names three effects. A smaller file needs less storage space, so a device holds more photographs or songs. It needs less bandwidth while it is being sent, so a connection can carry more streams at once and a video call does not starve the rest of the network. And it takes a shorter transmission time, so a page loads sooner, an email attachment sends before the server times out, and a download finishes while the user is still interested.

There is a fourth, practical reason that follows from the others: many systems impose hard limits. An email server may refuse an attachment over a fixed size, and a website that serves unoptimised images will feel slow on a mobile connection. Compression is how a file is made to fit inside those limits.

Compression is not free. It costs processing time to compress and decompress, and the more aggressive methods lose something. The choice of method is therefore a trade-off between size and fidelity, which is why the syllabus separates lossy from lossless.

  • Less storage space is needed for the same amount of content
  • Less bandwidth is used while the file is transferred
  • The transmission time is shorter, so the file arrives sooner
  • The file may fit inside a size limit imposed by an email server or a website

Lossy compression: give something up

Lossy compression reduces the file size by permanently removing data. The removed data cannot be recovered, so the original file cannot be recreated exactly from the compressed version, no matter what software is used afterwards.

The syllabus gives the standard examples. In an image, the resolution or the colour depth can be reduced: fewer pixels or fewer colours mean fewer bits to store, at the cost of detail or smooth shading. In a sound file, the sample rate or the sample resolution can be reduced: fewer or coarser samples mean less data, at the cost of accuracy and, at the extreme, audible distortion.

Lossy methods exploit what people do not notice. A photograph can lose subtle colour differences that the eye will not miss at normal viewing size, and a music track can lose frequencies that most listeners cannot hear. That is why lossy compression achieves far greater reductions than lossless: it is allowed to throw information away rather than merely to describe it more cleverly.

The consequence to state in an answer is that lossy compression is suitable for delivery and not for archiving or repeated editing. Each save of a lossy file loses a little more, so a photograph that is repeatedly opened, edited and saved degrades.

Lossless compression: keep every bit

Lossless compression reduces the file size without permanently losing any data. The original file can be recreated exactly, bit for bit, from the compressed version. Nothing is discarded; the data is described more efficiently.

Run length encoding (RLE) is the example named in the syllabus. A run of identical values is replaced by the value itself together with the number of times it repeats, so AAAAABBB becomes 5A3B. The same idea works on pixels: a row of 20 identical white pixels becomes the code for white followed by the count 20. Decompression reads each pair and writes the value back the stated number of times, which restores the original exactly.

RLE works well when there are long runs of the same value, such as a simple logo, a diagram, a scanned page of text or a black-and-white image. It works badly on a photograph, where neighbouring pixels are almost always different, so runs are short and the counts add almost as much data as they save. A lossless method that suits general files, such as the one used in a ZIP archive, looks for repeated patterns rather than repeated single values.

Lossless compression is the right choice when the file must survive intact: program code, text documents, spreadsheets, medical images and anything that will be edited again. The trade-off is that the reduction is smaller than a lossy method would achieve.

LossyLossless
What happens to dataSome data is permanently removedNo data is lost; it is stored more efficiently
Can the original be recreated exactly?NoYes
Typical examplesReducing resolution, colour depth, sample rate or sample resolutionRun length encoding, ZIP-style archive compression
Typical reductionLargeSmaller, and depends on how repetitive the data is
Suitable forDelivery: web images, streamed music and videoArchiving, text, code and files that will be edited again
Lossy removes data; lossless reorganises it. If the original must come back exactly, the method must be lossless.

Key terms you must be able to define

Bit
A single binary digit, 0 or 1. It is the smallest unit of data storage.
Nibble
4 bits, which is the number of bits represented by one hexadecimal digit.
Byte
8 bits, enough to store one ASCII character. There are 1024 bytes in a kibibyte.
Kibibyte (KiB)
1024 bytes. The kibibyte is the first unit above the byte and is a power-of-two multiple, unlike the decimal kilobyte.
Mebibyte (MiB)
1024 kibibytes, which is 1 048 576 bytes.
Gibibyte (GiB)
1024 mebibytes. Device storage and memory are often quoted in gibibytes.
Tebibyte, pebibyte and exbibyte
Each is 1024 of the unit before it: 1024 GiB in a TiB, 1024 TiB in a PiB and 1024 PiB in an EiB. They are used for large disks and data centres.
File size
The amount of storage a file needs, calculated for an uncompressed image as resolution × colour depth and for sound as sample rate × sample resolution × length.
Compression
Reducing the size of a file so that it needs less storage, uses less bandwidth and takes less time to transmit.
Lossy compression
Compression that permanently removes data, for example by reducing resolution, colour depth, sample rate or sample resolution, so the original cannot be recreated exactly.
Lossless compression
Compression that reduces the file size without permanently losing any data, so the original file can be recreated exactly. Run length encoding is an example.
Run length encoding (RLE)
A lossless method that stores a value once with the number of times it repeats, so AAAAABBB becomes 5A3B.

In context

2210 sets its questions inside systems a student already uses - a school network, a phone, a supermarket till, a vending machine, a website. These show how the theory is applied to a context you have not seen before, then you answer for the system you are given.

On a phone that says it is full

A phone with 64 GiB of storage holds a few thousand photographs at 3 MiB each. The operating system reports free space in GiB, the photo app reports each file in MiB, and the camera setting that reduces the image resolution is what makes each file smaller. Understanding the ladder is what turns 'storage full' into a calculation you can act on.

In an email attachment limit

An email server may reject any message over 25 MiB. A folder of uncompressed photographs at 4 MiB each will exceed that after six images, so the sender either compresses them lossily for sending or shares a link instead. The limit is expressed in the same units used in the calculation, which is why the answer must be converted before it can be compared.

In a website's images

A page that displays a 4000 × 3000 photograph in a 400-pixel-wide box is sending about a hundred times more pixel data than the screen can show. Reducing the resolution to fit the display and applying lossy compression cuts the download dramatically, which is why the page loads quickly and uses less of a mobile data allowance.

In a music streaming service

A streaming service sends lossy-compressed audio, because a smaller file needs less bandwidth and starts playing sooner. The same track sold for download may be offered in a lossless format at several times the size, for listeners who want an exact copy. Both choices are reasonable; they optimise for different things.

In a backup of text files

A folder of source code or word-processed documents compresses well with a lossless method, often to less than half its original size, because text contains many repeated patterns. Nothing may be lost, since a single changed character would break the program or the document.

Flashcards

Click a card to flip it. Mark honestly — the tracker uses this.

Q1How many bits are in a nibble, a byte, and a kibibyte?
A nibble is 4 bits, a byte is 8 bits and a kibibyte is 1024 bytes, which is 8192 bits.
Q2List the storage units from the bit upwards.
Bit, nibble, byte, kibibyte (KiB), mebibyte (MiB), gibibyte (GiB), tebibyte (TiB), pebibyte (PiB), exbibyte (EiB).
Q3How many kibibytes are in a mebibyte, and how many mebibytes in a gibibyte?
1024 KiB in a MiB and 1024 MiB in a GiB. Every step up the ladder is a multiple of 1024.
Q4Why is the multiplier 1024 rather than 1000?
Storage is addressed in binary, and 1024 is 2 to the power 10, the first power of two above a thousand. The syllabus requires 1024 to be used in calculations.
Q5What is the formula for the size of an uncompressed image file?
File size in bits = width × height × colour depth. Then divide by 8 for bytes and by 1024 for each step up the units.
Q6What is the formula for the size of an uncompressed sound file?
File size in bits = sample rate × sample resolution × length in seconds. Then divide by 8 for bytes and by 1024 for each step up.
Q7An image is 512 × 512 pixels at 8-bit colour depth. What is its size in KiB?
512 × 512 = 262 144 pixels; × 8 = 2 097 152 bits; ÷ 8 = 262 144 bytes; ÷ 1024 = 256 KiB.
Q8A sound file is recorded at 8192 samples per second, 16-bit resolution, for 4 seconds. What is its size in KiB?
8192 × 16 × 4 = 524 288 bits; ÷ 8 = 65 536 bytes; ÷ 1024 = 64 KiB.
Q9Why is data compression needed?
To reduce the size of a file so that less storage space is needed, less bandwidth is used during transfer and the transmission time is shorter.
Q10What is lossy compression?
Compression that reduces the file size by permanently removing data, for example by reducing resolution, colour depth, sample rate or sample resolution. The original cannot be recreated exactly.
Q11What is lossless compression?
Compression that reduces the file size without permanent loss of data, so the original file can be recreated exactly. Run length encoding is an example.
Q12How does run length encoding work, and when does it work badly?
A run of identical values is replaced by the value and the number of repeats, so AAAAABBB becomes 5A3B. It works badly on photographs, where neighbouring pixels rarely match so the runs are short.
0 of 12 marked as known

Exam-style questions

8 questions, 25 marks. Write your answer and press Mark my answer — it is marked against the scheme and tells you which points you made and what would gain the next mark. You can still reveal the scheme and mark it yourself instead.

StateAO11 mark
State how many bits there are in a nibble and how many bits there are in a byte.

Mark scheme — tick each point you actually made

Examiner tip: Both values are needed for the single mark. A nibble is one hexadecimal digit and a byte is one ASCII character, which is a useful way to remember them.
CalculateAO22 marks
A hard disk has a capacity of 2 TiB. Calculate its capacity in GiB and in MiB. Show your working.

Mark scheme — tick each point you actually made

Examiner tip: Going down the ladder means multiplying, not dividing. Each step is a factor of 1024, so two steps from TiB to MiB is 1024 squared.
CalculateAO24 marks
An uncompressed image has a resolution of 640 × 480 pixels and a colour depth of 16 bits. Calculate the file size of the image in KiB. Show your working.

Mark scheme — tick each point you actually made

Examiner tip: Show the pixel count as its own line. Substituting the product straight into the multiplication is where most arithmetic slips happen, and the separate line is often a mark.
CalculateAO24 marks
An uncompressed sound recording has a sample rate of 8192 samples per second, a sample resolution of 24 bits and a length of 8 seconds. Calculate the file size in KiB. Show your working.

Mark scheme — tick each point you actually made

Examiner tip: The length in seconds must appear in the calculation. Check the unit asked for before you stop dividing, and give the unit with the answer.
ExplainAO23 marks
Explain why a website reduces the size of the images it displays.

Mark scheme — tick each point you actually made

Examiner tip: Three distinct effects are needed: storage, bandwidth and transmission time. Repeating 'it loads faster' in three different ways scores once.
ExplainAO24 marks
Explain the difference between lossy and lossless compression, giving one example of each and one situation where each would be appropriate.

Mark scheme — tick each point you actually made

Examiner tip: Use the syllabus wording: 'permanently removing data' and 'without permanent loss of data'. Then make the situations clearly different, not two versions of the same example.
DescribeAO23 marks
Describe how run length encoding compresses a file, using a simple example.

Mark scheme — tick each point you actually made

Examiner tip: Say what the two parts of each code mean — value and count — and finish by stating that the original is restored exactly. That last point is what makes the method lossless.
EvaluateAO34 marks
A student has 60 photographs, each about 4 MiB, to send to a friend over a slow connection. The student is considering sending them lossily compressed at roughly one tenth of the size. Evaluate this decision.

Mark scheme — tick each point you actually made

Examiner tip: An evaluate answer needs a judgement, not just both sides. Say under what condition the decision is right and under what condition it is not, and offer an alternative.

Exam technique for this topic

  • Write the formula before you substitute the numbers. A marker can award the method even when the arithmetic slips, and seeing the formula makes it obvious which quantity you have used.
  • Divide by 8 first for bits to bytes, then by 1024 for each step between units. Never mix the two, and never use 1000 anywhere in the chain.
  • Check the unit in the question and finish there. If it asks for KiB, do not convert on to MiB 'to be tidy', and do put the unit in your answer.
  • For a sound calculation, multiply by the length of the track in seconds. Leaving it out gives the size of one second, which is the most common single error in this topic.
  • For compression questions, name the effect as well as the method: less storage, less bandwidth and a shorter transmission time are three separate marks in many schemes.
  • For lossy versus lossless, use the exact phrases: 'permanently removes data' and 'without permanent loss of data'. Those phrases are the definitions the syllabus uses.

Why students lose marks here

A student wroteA student calculated 786 432 bytes ÷ 1000 and wrote the answer as 786.4 KiB.
Why it loses marksThe step between storage units is 1024, not 1000, because storage is addressed in binary and 1024 is 2 to the power 10. The syllabus states explicitly that calculations must use 1024.
The answer that scores786 432 bytes ÷ 1024 = 768 KiB. Use 1024 for every step between units above the byte; the factor of 1000 belongs to decimal units such as the kilogram, not to kibibytes.
A student wroteA student calculated an image file as 512 × 512 × 8 = 2 097 152 and answered '2 097 152 KiB'.
Why it loses marksThe result of the multiplication is in bits, not kibibytes. The student skipped both conversions: dividing by 8 to reach bytes and by 1024 to reach KiB. The number is correct but the unit makes the answer wrong by a factor of 8192.
The answer that scores512 × 512 = 262 144 pixels; × 8 = 2 097 152 bits; ÷ 8 = 262 144 bytes; ÷ 1024 = 256 KiB. Always finish the chain and label the unit at each step so the final unit is the one the question asked for.
A student wroteA student calculated the size of an 8-second sound file as 8192 × 16 = 131 072 bits.
Why it loses marksThe length of the track was left out. The multiplication gives the number of bits for one second of audio at that sample rate and resolution; the file is eight times larger.
The answer that scoresFile size = sample rate × sample resolution × length = 8192 × 16 × 8 = 1 048 576 bits; ÷ 8 = 131 072 bytes; ÷ 1024 = 128 KiB. Check that the length in seconds appears in the calculation before you divide anything.
A student wroteA student wrote: 'Lossy compression reduces the file size and the original file can be restored from it, which is why it is used for photographs.'
Why it loses marksThe first half is right and the second half contradicts it. Lossy compression permanently removes data, so the original cannot be restored exactly. Confusing the two methods is the most common compression error.
The answer that scoresLossy compression reduces the file size by permanently removing data, for example by reducing the resolution or colour depth of an image, so the original cannot be recreated exactly. Lossless compression, such as run length encoding, reduces the file size without permanent loss, so the original can be restored.
A student wroteA student wrote: 'Run length encoding is a lossy method because it replaces the data with a code.'
Why it loses marksReplacing data with a code is not the same as discarding it. RLE stores the value and the count, and decompression writes the value back the stated number of times, so every original value is recovered.
The answer that scoresRun length encoding is lossless: AAAAABBB becomes 5A3B, and decompression expands 5A3B back to AAAAABBB exactly. The data is described more compactly, not removed. RLE is only ineffective when runs are short, as in a photograph, not inaccurate.
A student wroteA student compared a 20 MiB folder with a 25 MB email limit and concluded the folder would fit.
Why it loses marksMiB and MB are different units: a mebibyte is 1024 kibibytes while a megabyte is 1000 kilobytes, so 20 MiB is about 21 MB and the comparison is not the simple one it appears to be. Mixing the symbols is how a correct calculation ends in a wrong decision.
The answer that scoresConvert both quantities to the same unit before comparing. 20 MiB is 20 × 1024 × 1024 = 20 971 520 bytes, which is about 21 MB, so it is still under a 25 MB limit but with much less headroom than the bare numbers suggest. Label the unit every time and convert before deciding.

Where this fits in O Level Computer Science 2210

This page is one topic of Cambridge O Level Computer Science 2210. O Level Computer Science 2210 is the course home: every area and every topic in Cambridge's own order, the papers you sit and what each one tests, and the exam-practice tools. The full topic list, with each topic linked to its revision page, is on the O Level Computer Science 2210 syllabus page.