Data compression reduces the number of bits required to store or transmit data. Lossless compression allows the original data to be reconstructed exactly, whereas lossy compression permanently removes some data to achieve a greater reduction in file size.
How data compression works
A compression algorithm encodes data using fewer bits, often by removing redundancy. This reduces storage requirements and the time or bandwidth needed to transmit a file, linking compression to computer hardware and operation in subtopic A1.1.
For example, run-length encoding (RLE) replaces repeated values with a value and its frequency. The sequence AAAAABB could be stored as 5A2B. Other lossless methods assign shorter codes to frequently occurring data.
A compression ratio can be defined as:
If a file becomes , its compression ratio is .
| Feature | Lossless compression | Lossy compression |
|---|---|---|
| Reconstruction | Restores the original data exactly | Cannot restore all original data |
| Method | Removes redundancy without discarding information | Discards data judged less important to the user |
| Typical uses | Program files, text, databases and medical records | Photographs, audio and video |
| Examples | PNG, ZIP, RLE and Huffman coding | JPEG, MP3 and some video codecs |
| Main trade-off | Usually produces a smaller reduction | Usually produces much smaller files but may reduce quality |
Lossless compression is required when every bit matters. A program compressed using a lossy method could contain changed instructions and fail to execute. Lossy compression is suitable for media because small changes may be unnoticeable, although excessive compression can create visible or audible artefacts.
A common misconception is that lossy compression deletes only redundant data. It actually removes information permanently; redundancy removal without information loss is characteristic of lossless compression.
IB exam technique
For a compare question, state paired differences rather than giving two separate definitions. Include reconstruction, file size, quality and an appropriate use case, then justify why that use case can or cannot tolerate discarded data.