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.
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.
| Unit | Symbol | How many of the previous unit |
|---|---|---|
| Bit | b | one binary digit |
| Nibble | — | 4 bits |
| Byte | B | 8 bits, or 2 nibbles |
| Kibibyte | KiB | 1024 bytes |
| Mebibyte | MiB | 1024 KiB |
| Gibibyte | GiB | 1024 MiB |
| Tebibyte | TiB | 1024 GiB |
| Pebibyte | PiB | 1024 TiB |
| Exbibyte | EiB | 1024 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.
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.
| From | To | Operation |
|---|---|---|
| Bits | Bytes | ÷ 8 |
| Bytes | KiB | ÷ 1024 |
| KiB | MiB | ÷ 1024 |
| MiB | GiB | ÷ 1024 |
| GiB | MiB | × 1024 |
| MiB | KiB | × 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.
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.
| Quantity | Formula | Unit of the result |
|---|---|---|
| Image size | width × height × colour depth | bits, before conversion |
| Sound size | sample rate × sample resolution × length in seconds | bits, before conversion |
| Bits to bytes | ÷ 8 | bytes |
| Bytes to KiB | ÷ 1024 | KiB |
| KiB to MiB | ÷ 1024 | MiB |
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.
| Lossy | Lossless | |
|---|---|---|
| What happens to data | Some data is permanently removed | No data is lost; it is stored more efficiently |
| Can the original be recreated exactly? | No | Yes |
| Typical examples | Reducing resolution, colour depth, sample rate or sample resolution | Run length encoding, ZIP-style archive compression |
| Typical reduction | Large | Smaller, and depends on how repetitive the data is |
| Suitable for | Delivery: web images, streamed music and video | Archiving, text, code and files that will be edited again |
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.
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.
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.
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.
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.
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.
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.
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
Mark scheme — tick each point you actually made
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
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.