logo

Cambridge IGCSE Computer Science revision notes

Data storage and compression Revision Notes

Cambridge IGCSE revision notes for Data storage and compression.

At a glance

revision notes

Resource type

Topic

Data storage and compression

CambridgeIGCSEComputer ScienceData representation

Complete revision guide 1 of 4

Units of Data Storage and Their Relationships

This note explains the hierarchy of data storage units from bits to exbibytes, detailing how each unit relates to the next by powers of two, and why understanding these units is essential for accurate data measurement and calculations in computer science.

Syllabus source

Section 3, Topic 1.3, page 13, objective 1.3.1

Open source document ↗

What you should be able to do

  • ✓Identify and define the basic units of data storage: bit, nibble, and byte.
  • ✓Understand the binary-based progression of larger data units: kibibyte, mebibyte, gibibyte, tebibyte, pebibyte, and exbibyte.
  • ✓Calculate the number of smaller units contained within larger units using powers of 2, specifically 1024 as the base.
  • ✓Apply knowledge of data units to practical examples involving data size and storage capacity.
1

Fundamental Units: Bits, Nibbles, and Bytes

Data storage begins at the smallest unit called a bit, which can hold a value of either 0 or 1. This binary digit is the foundation of all digital data.

A nibble consists of 4 bits. It is half of a byte and can represent 16 different values (2^4).

A byte is made up of 8 bits and is the standard unit for measuring data. For example, a single ASCII character is typically stored in one byte, which means it uses 8 bits to represent letters, digits, or symbols.

  • 1 bit = 1 binary digit (0 or 1)
  • 1 nibble = 4 bits
  • 1 byte = 8 bits
2

Binary Multiples: From Bytes to Kibibytes and Beyond

Computers use binary systems, so data units increase in powers of 2 rather than 10. This means that each larger unit is 1024 times the size of the previous one, not 1000.

A kibibyte (KiB) is 1024 bytes. This is slightly larger than a kilobyte (kB), which is often used in decimal systems as 1000 bytes, but in computing, kibibyte is the precise binary unit.

Following this pattern, a mebibyte (MiB) is 1024 kibibytes, a gibibyte (GiB) is 1024 mebibytes, and so on, continuing through tebibytes (TiB), pebibytes (PiB), and exbibytes (EiB). Each step multiplies the previous unit by 1024, reflecting the binary nature of computer memory and storage.

  • 1 KiB = 1024 bytes
  • 1 MiB = 1024 KiB
  • 1 GiB = 1024 MiB
  • 1 TiB = 1024 GiB
  • 1 PiB = 1024 TiB
  • 1 EiB = 1024 PiB
3

Why Use 1024 Instead of 1000?

The base 1024 arises because computer memory is organised in powers of 2. Since 2^10 = 1024, it is natural to use 1024 as the multiplier between units.

Using 1000 as a multiplier is common in decimal systems and some marketing materials, but it can cause confusion when calculating actual memory sizes.

For example, a 1 GiB memory module contains 1024 × 1024 × 1024 bytes, which equals 1,073,741,824 bytes, not exactly 1,000,000,000 bytes. This difference is important when precise calculations are required.

  • 1 KiB = 2^10 bytes = 1024 bytes
  • 1 MiB = 2^20 bytes = 1,048,576 bytes
  • 1 GiB = 2^30 bytes = 1,073,741,824 bytes
4

Practical Examples of Data Unit Conversions

Example 1: How many bits are in 3 bytes? Since 1 byte = 8 bits, 3 bytes = 3 × 8 = 24 bits.

Example 2: How many bytes are in 5 KiB? Since 1 KiB = 1024 bytes, 5 KiB = 5 × 1024 = 5120 bytes.

Example 3: How many MiB are in 2 GiB? Since 1 GiB = 1024 MiB, 2 GiB = 2 × 1024 = 2048 MiB.

  • 3 bytes = 24 bits
  • 5 KiB = 5120 bytes
  • 2 GiB = 2048 MiB
5

Importance of Understanding Data Units in Computing

Knowing these units and their relationships is essential for tasks such as calculating file sizes, memory requirements, and data transfer rates.

For instance, when downloading a file, the size might be given in megabytes (MB), but the actual storage used on a computer might be measured in mebibytes (MiB), which can cause slight differences in reported sizes.

Understanding these units helps avoid errors in programming, system design, and troubleshooting storage issues.

  • Accurate data size calculations require correct unit conversions
  • Helps in understanding storage device capacities
  • Essential for programming and data management

At-a-glance summary

Comparison table

StepDetailExampleExam Use
Identify unitStart with smallest unit: bit1 bit stores 0 or 1Define bit clearly in answers
Convert unitsUse 1024 as multiplier between units1 KiB = 1024 bytesShow multiplication by 1024 in calculations
Calculate sizeMultiply units to find total size3 bytes = 3 × 8 = 24 bitsWrite out formula and substitution
Recognise larger unitsKnow order: KiB, MiB, GiB, TiB, PiB, EiB1 GiB = 1024 MiBList units in correct order when asked

Active recall

Quick check

1. How many bits are there in 2 bytes?

2 bytes × 8 bits/byte = 16 bits.

2. What is the size of 1 MiB in bytes?

1 MiB = 1024 KiB × 1024 bytes = 1,048,576 bytes.

3. Convert 4 GiB to MiB.

4 GiB × 1024 MiB/GiB = 4096 MiB.

4. Why is 1024 used instead of 1000 when converting between data units?

Because computer memory is based on powers of 2, and 2^10 = 1024, making 1024 the natural binary multiple.

Complete revision guide 2 of 4

Calculating File Sizes for Images and Sound Files

This note explains how to calculate the file size of images and sound files using key parameters such as resolution, colour depth, sample rate, bit depth, and track length. It emphasises the use of 1024 as the base for unit conversions and introduces the role of compression in reducing file sizes.

Syllabus source

Section 3, Topic 1.3, page 13, objective 1.3.2

Open source document ↗

What you should be able to do

  • ✓Understand the factors affecting image file size: resolution and colour depth.
  • ✓Understand the factors affecting sound file size: sample rate, bit depth, and track length.
  • ✓Use 1024 as the base unit for converting between bytes and larger units.
  • ✓Apply formulas to calculate file sizes for images and sound files.
  • ✓Recognise the purpose and effect of compression on file size.
1

Understanding Image File Size

An image file's size depends primarily on its resolution and colour depth. Resolution is the total number of pixels, calculated by multiplying the width by the height of the image in pixels. Colour depth is the number of bits used to represent the colour of each pixel.

To find the uncompressed image file size in bits, multiply the total number of pixels by the colour depth (bits per pixel). To convert bits to bytes, divide by 8, since 1 byte = 8 bits.

For example, an image with a resolution of 1920 pixels wide and 1080 pixels high, and a colour depth of 24 bits per pixel (true colour), has: 1920 × 1080 = 2,073,600 pixels. The total bits = 2,073,600 × 24 = 49,766,400 bits. Dividing by 8 gives 6,220,800 bytes.

  • Image size (bits) = width × height × colour depth
  • Convert bits to bytes by dividing by 8
  • Use 1024 to convert bytes to kilobytes and beyond
2

Calculating Sound File Size

Sound files are made up of samples taken at regular intervals (sample rate), each sample having a bit depth (bits per sample) that determines the sound quality. The track length (duration in seconds) also affects the file size.

To calculate the uncompressed sound file size in bits, multiply the sample rate (samples per second) by the bit depth (bits per sample) and then by the track length (seconds). If the sound is stereo, multiply by the number of channels (usually 2).

For example, a stereo sound file with a sample rate of 44,100 Hz, bit depth of 16 bits, and length of 3 minutes (180 seconds) has: 44,100 × 16 × 180 × 2 = 254,016,000 bits. Dividing by 8 gives 31,752,000 bytes.

  • Sound size (bits) = sample rate × bit depth × track length × channels
  • Divide bits by 8 to get bytes
  • Use 1024 for converting bytes to larger units
3

Using 1024 as the Base Unit for Data Storage

In computer science, data storage units use powers of 2, so 1 kilobyte (KB) is 1024 bytes, not 1000. Similarly, 1 megabyte (MB) is 1024 KB, and so on.

When converting bytes to kilobytes, divide by 1024. For example, 6,220,800 bytes ÷ 1024 = 6075 KB (approximately 5.94 MB).

This base-1024 system is important for accurate file size calculations and comparisons.

  • 1 KB = 1024 bytes
  • 1 MB = 1024 KB
  • Always use 1024, not 1000, for conversions
4

Role of Compression in File Size Reduction

Compression reduces file size by encoding data more efficiently. There are two main types: lossless and lossy.

Lossless compression reduces file size without losing any data, allowing exact reconstruction. Examples include PNG for images and FLAC for audio.

Lossy compression reduces file size by permanently removing some data, which may reduce quality. Examples include JPEG for images and MP3 for audio files. This is useful when smaller file size is more important than perfect quality.

  • Compression reduces file size to save storage and bandwidth
  • Lossless compression preserves all original data
  • Lossy compression removes some data to reduce size further
5

Worked Example: Calculating an Image File Size

Calculate the file size of an uncompressed image with resolution 1280 × 720 pixels and colour depth 16 bits per pixel.

Step 1: Calculate total pixels: 1280 × 720 = 921,600 pixels.

Step 2: Calculate total bits: 921,600 × 16 = 14,745,600 bits (since each pixel uses 16 bits).  Step 3: Convert bits to bytes: 14,745,600 ÷ 8 = 1,843,200 bytes (because 8 bits = 1 byte).  Step 4: Convert bytes to kilobytes: 1,843,200 ÷ 1024 ≈ 1800 KB.  Step 5: Convert kilobytes to megabytes: 1800 ÷ 1024 ≈ 1.76 MB.  Final answer: The image file size is approximately 1.76 megabytes (MB).  Common error: Using 1000 instead of 1024 for conversions leads to underestimating file size.

  • Calculate pixels × colour depth to get bits
  • Divide bits by 8 to get bytes
  • Divide bytes by 1024 to get KB, then MB

At-a-glance summary

Comparison table

StepDetailExampleExam Use
Calculate total data unitsMultiply resolution or sample rate by bit depthImage: 1920×1080×24 bitsShow formula and substitution
Convert bits to bytesDivide total bits by 849,766,400 bits ÷ 8 = 6,220,800 bytesInclude units in answer
Convert bytes to KB/MBDivide by 1024 for each step6,220,800 bytes ÷ 1024 = 6075 KBUse 1024, not 1000
Apply compressionRecognise compression reduces file sizeJPEG compresses images, MP3 compresses audioState compression effect in answers

Active recall

Quick check

1. How do you calculate the file size in bits of an image?

Multiply the image resolution (width × height) by the colour depth (bits per pixel).

2. What is the formula to calculate the size of a sound file in bits?

Sample rate × bit depth × track length (seconds) × number of channels.

3. Why do we use 1024 instead of 1000 when converting bytes to kilobytes?

Because data storage units are based on powers of 2, so 1 KB = 1024 bytes, not 1000.

4. What is the difference between lossy and lossless compression?

Lossy compression removes some data permanently, reducing quality; lossless compression reduces size without losing any data.

Complete revision guide 3 of 4

Understanding the Reasons for and Benefits of Data Compression

Data compression reduces the size of digital data, leading to lower bandwidth usage, reduced storage requirements, and faster transmission times. This note explains why compression is necessary, how it benefits data handling, and illustrates these effects with practical examples.

Syllabus source

Section 3, Topic 1.3, page 13, objective 1.3.3

Open source document ↗

What you should be able to do

  • ✓Explain why data compression is used in computing and communications.
  • ✓Describe how compression reduces bandwidth consumption.
  • ✓Understand how compression decreases storage space requirements.
  • ✓Explain how compression shortens data transmission times.
1

Why Data Compression Is Necessary

Digital data such as images, audio, and video files can be very large. Transmitting or storing these large files without compression requires significant bandwidth and storage capacity. For example, a high-resolution image might be several megabytes in size, and sending it over a slow internet connection could take a long time. Compression reduces the amount of data that must be handled, making processes more efficient.

  • Large files require more storage space and bandwidth.
  • Uncompressed data can slow down transmission and increase costs.
  • Compression optimises resource use in networks and storage devices.
2

How Compression Reduces Bandwidth Usage

Bandwidth is the maximum rate of data transfer over a network. When data is compressed, fewer bits are sent for the same information, so less bandwidth is consumed. For instance, compressing a 10 MB file to 2 MB means only 20% of the original data is transmitted, freeing bandwidth for other uses and reducing network congestion.

  • Compression lowers the number of bits transmitted.
  • Less bandwidth is needed for the same content.
  • This improves network efficiency and reduces transmission costs.
3

Decreasing Storage Requirements Through Compression

Storage devices have limited capacity. Compressing files reduces their size, allowing more files to be stored in the same space. For example, a 500 MB video compressed to 100 MB uses only one-fifth of the original storage space, enabling devices to hold more data or use smaller storage media.

  • Compressed files occupy less disk space.
  • More data can be stored on the same device.
  • This can reduce the need for additional storage hardware.
4

Shortening Transmission Times with Compression

Transmission time depends on the size of the data and the speed of the connection. By reducing file size, compression shortens the time needed to send data. For example, if a file takes 10 minutes to send uncompressed, compressing it to half its size can reduce transmission time to about 5 minutes, assuming constant bandwidth.

  • Smaller files transmit faster over networks.
  • Compression reduces delays in data transfer.
  • This is critical for streaming and real-time communication.
5

Summary of Compression Benefits

Overall, data compression improves efficiency in digital communication and storage by reducing file sizes. This leads to lower bandwidth consumption, less storage space needed, and faster data transmission. These benefits are essential in environments with limited resources or where speed is critical.

  • Reduces file size for efficient handling.
  • Lowers bandwidth usage and network load.
  • Decreases storage space requirements.
  • Speeds up data transmission times.

At-a-glance summary

Comparison table

StepDetailExampleExam Use
Identify large dataRecognise files that consume significant storage or bandwidthA 100 MB video fileExplain why large files need compression
Apply compressionUse algorithms to reduce file sizeCompressing a 10 MB image to 2 MBDescribe effects on bandwidth and storage
Transmit compressed dataSend smaller files over networksStreaming compressed audio instead of raw audioState how transmission time is reduced
Store compressed filesSave smaller files on storage devicesSaving compressed documents on a USB driveExplain storage space savings

Active recall

Quick check

1. What is the main purpose of data compression?

To reduce the size of data so it uses less storage space and bandwidth, and transmits faster.

2. How does compression affect bandwidth usage?

It lowers bandwidth usage by reducing the number of bits sent over the network.

3. Why does compression decrease storage requirements?

Because compressed files take up less space on storage devices than uncompressed files.

4. How does compression shorten transmission times?

Smaller files require less time to send over a network, so transmission is faster.

Complete revision guide 4 of 4

File Compression: Lossy and Lossless Methods

This note explains how files can be compressed using lossy and lossless methods. Lossy compression reduces file size by permanently removing some data, affecting quality, while lossless compression reduces file size without losing any data, allowing perfect reconstruction. Examples and a worked calculation illustrate these concepts.

Syllabus source

Section 3, Topic 1.3, page 14, objective 1.3.4

Open source document ↗

What you should be able to do

  • ✓Understand the difference between lossy and lossless compression.
  • ✓Explain how lossy compression permanently removes data to reduce file size.
  • ✓Describe how lossless compression reduces file size without data loss.
  • ✓Identify examples of lossy and lossless compression methods.
  • ✓Apply knowledge of compression to practical file size calculations.
1

Introduction to File Compression

File compression is a technique used to reduce the size of digital files, making storage and transmission more efficient. Compression is essential because large files require more storage space and take longer to send over networks. There are two main types of compression: lossy and lossless, each with different effects on the data and quality of the file.

  • Compression reduces file size to save storage and bandwidth.
  • Two main types: lossy and lossless compression.
2

Lossy Compression: Permanent Data Removal

Lossy compression reduces file size by permanently removing some data from the original file. This removal is irreversible, meaning the original file cannot be perfectly restored. The data removed is usually less noticeable information, such as subtle colour variations in images or frequencies inaudible to humans in audio files. This method achieves higher compression ratios but at the cost of some quality loss.

For example, reducing the resolution of an image or lowering the sample rate of an audio file are common lossy techniques. JPEG is a widely used lossy image format, and MP3 is a common lossy audio format.

Lossy compression is suitable when perfect accuracy is not critical, such as streaming videos or storing photos for casual viewing.

  • Permanently removes some data to reduce file size.
  • Quality decreases as more data is removed.
  • Examples: JPEG images, MP3 audio.
  • Commonly used for images, audio, and video where some quality loss is acceptable.
3

Lossless Compression: Data Retained Exactly

Lossless compression reduces file size without losing any data, allowing the original file to be perfectly reconstructed from the compressed version. This is important for files where accuracy is critical, such as text documents, executable programs, or some image formats like PNG.

Lossless methods work by finding and encoding patterns or repetitions in the data more efficiently. One example is run-length encoding (RLE), which compresses sequences of repeated data by storing the data value and the number of repetitions instead of each individual item.

Because no data is lost, lossless compression typically achieves lower compression ratios than lossy methods but preserves full quality.

  • No data is lost; original file can be perfectly restored.
  • Uses pattern encoding like run-length encoding.
  • Examples: PNG images, ZIP files.
  • Used when data integrity is essential.
4

Run-Length Encoding (RLE) as a Lossless Method

Run-length encoding is a simple lossless compression technique that replaces consecutive repeated values with a single value and a count. For example, a sequence of 10 consecutive 'A's would be stored as 'A10' instead of 'AAAAAAAAAA'.

This method is effective when data contains many repeated values but less effective for data with high variability.

RLE is often used in simple graphic images or as part of more complex compression algorithms.

  • Replaces repeated data with value and count.
  • Effective for data with many repeats.
  • Example: 'BBBBB' becomes 'B5'.
5

Worked Example: Calculating Compressed File Size Using RLE

Suppose a file contains the following sequence of characters: AAAABBBCCDAA. Using run-length encoding, we compress this sequence by counting consecutive repeated characters.

Step 1: Identify runs: 'A' repeated 4 times, 'B' repeated 3 times, 'C' repeated 2 times, 'D' repeated 1 time, 'A' repeated 2 times.

Step 2: Encode runs as pairs: A4 B3 C2 D1 A2. Each pair consists of a character and a count. If each character and count is stored as one byte, the compressed file size is 10 bytes (5 pairs × 2 bytes each). The original file size is 12 bytes (12 characters × 1 byte each). Thus, compression reduces the file size from 12 bytes to 10 bytes, saving 2 bytes or about 16.7%. This is a modest reduction, but for longer sequences with more repeats, savings increase significantly.

  • Original sequence: AAAABBBCCDAA (12 bytes).
  • Compressed sequence: A4 B3 C2 D1 A2 (10 bytes).
  • Compression ratio: 10/12 = 0.83 (17% size reduction).

At-a-glance summary

Comparison table

AspectLossy CompressionLossless CompressionExample Formats
Data lossPermanently removes some dataNo data loss; original data fully recoverableJPEG (lossy), MP3 (lossy); PNG (lossless), ZIP (lossless)
Effect on qualityQuality decreases as data is removedQuality remains identical to originalJPEG images may show artefacts; PNG images remain sharp
Compression ratioGenerally higher compression ratiosLower compression ratiosMP3 files much smaller than WAV; ZIP files smaller but less than MP3
Use casesMultimedia where some quality loss is acceptableDocuments, software, images needing exact dataStreaming video, music; Text files, software archives

Active recall

Quick check

1. What is the main difference between lossy and lossless compression?

Lossy compression permanently removes some data and reduces quality, while lossless compression reduces file size without losing any data, allowing perfect reconstruction.

2. Give one example of a lossy compression format and one of a lossless format.

JPEG is an example of lossy compression; PNG is an example of lossless compression.

3. How does run-length encoding compress data?

By replacing sequences of repeated data with a single value and a count of repetitions.

4. Why might lossy compression be preferred for video files?

Because it achieves much smaller file sizes by removing less noticeable data, which is acceptable for viewing purposes.

5. Calculate the compressed size of the sequence 'CCCCCCDDDD' using run-length encoding if each character and count is stored as one byte.

The sequence has 'C' repeated 6 times and 'D' repeated 4 times, so compressed as C6 D4. Each pair is 2 bytes, so total compressed size is 4 bytes, compared to original 10 bytes.

Revision hubs

Keep studying from the right hub