Compression reduces the size of a file. Smaller files require less storage space and transfer faster over networks. There are two types of compression: lossless and lossy. This lesson covers lossless.
In lossless compression, the original data can be perfectly reconstructed from the compressed file — no data is permanently removed. Decompressing the file gives back exactly the original data, bit for bit.
Lossless compression is essential when every bit of the original must be preserved, for example text files, executable programs, medical images, and source code.
Run-Length Encoding (RLE) is a simple lossless algorithm that replaces runs of repeated values with a count-value pair.
RLE gives the best compression ratio when data contains many consecutive repeated values — for example:
RLE can actually increase file size when data has very few repeated values — for example, a photograph with many different colours in each row (ABCDEABCDE...). Each value gets a (1, value) pair, which uses more space than the original.
Other lossless algorithms (like LZW, used in GIF and ZIP) build a dictionary of repeated patterns in the data and replace each occurrence with a shorter code. The decompressor uses the same dictionary to reconstruct the original.
| Format | Type | Notes |
|---|---|---|
| PNG | Image | Lossless; best for screenshots, logos, diagrams with flat colours |
| GIF | Image | Lossless LZW; limited to 256 colours; supports animation |
| BMP | Image | Usually uncompressed (raw bitmap) |
| FLAC | Audio | Lossless audio; exact original waveform preserved |
| ZIP / RAR | Archive | General-purpose lossless compression for any files |
Compression ratio = original size ÷ compressed size. A ratio of 4:1 means the compressed file is four times smaller than the original.
Space saving % = (1 − compressed size / original size) × 100%
8 questions · 16 marks
| Term | Definition |
|---|
Timed exam conditions.