Representing text, images and soundCompression

Learn how text, images and sound are converted into binary so they can be processed by a computer and how images and sound are compressed to create smaller files.

Part ofComputer ScienceData representation

Compression

Why compress files?

Processing power and storage space is very valuable on a computer. To get the best out of both, it can mean that we need to reduce the file size of text, image and audio in order to transfer it more quickly and so that it takes up less storage space.

In addition, large files take a lot longer to or which leads to web pages, songs and videos that take longer to load and play when using the internet.

addresses these issues.

Any kind of data can be compressed. There are two main types of compression: lossy and lossless.

Lossy compression

Lossy compression removes some of a file’s original data in order to reduce the file size. This might mean reducing the numbers of colours in an image or reducing the number of samples in a sound file. This can result in a small loss of quality of an image or sound file.

A popular lossy compression method for images is , which is why most images on the internet are JPEG images. A popular lossy compression method for sounds is .

Once a file has been compressed using lossy compression, the discarded data cannot be retrieved again.

Lossless compression

Lossless compression doesn’t reduce the quality of the file at all. No data is lost, so lossless compression allows a file to be recreated exactly as it was when originally created.

There are various algorithms for doing this, usually by looking for patterns in the data that are repeated. files are an example of lossless compression.

The space savings of lossless compression are not as good as they are with lossy compression.

Lossy compression removes some of a file’s original data in order to reduce the file size. Lossless compression doesn't reduce the quality of the file at all and no data is lost.

More guides on this topic