How Does Data Compression Make Files Smaller?

by Carson
232 views
Compressed image vs uncompressed image

Many people know it’s very slow to deal with files that take up a few gigabytes. That’s why data compression appears. If you’re reading this article, you’re probably curious about how computers compress files and make them smaller. So, let’s get started.

Types of File Compression

To understand how it works, we must find out the types of file compression. So, there are two types of data compression, which are lossless and lossy compression.

The names of the types are self-explanatory: Lossless compression means the file can be 100% reconstructed upon decompression. In contrast, lossy compression removes some quality and details from the file. Although lossy ones usually have smaller file sizes, they are only suitable for multimedia files, not text files or code.

Moreover, lossy compression is irreversible. Once you compressed it, you can’t go back. However, if you’ve uploaded your image file to your cloud service provider or image editing platform, you can hopefully download the original file again.

Basic Algorithms

When we talk about the fundamental algorithms of data compression, it’s where the real fun begins. The first method introduced in this article removes redundant information, and it’s a type of lossless compression.

If we have a string of characters that contains four consecutive “98”s, why don’t we write that like “’98’ * 4” instead of “98989898”? This works really well for images). If it’s a plain color image, we can do it at only one pixel, a few chunks of code and metadata, and it’s done. That photo is much smaller than a raw 4096 * 4096 image.

That is a very extreme case, but this method can delete a significant number of nearby pixels with the same color.

Moreover, if the compressor recognizes some patterns in the file, they might write code instead of individual data points to reduce the size. The larger the pattern, the more space it can save.

Adding code can compress files if there are patterns (or even animations)
Image Credit: Canva
Video Compression

Other than compressing every frame of imagery and audio, videos often have better ways for compression. For instance, they may copy some frames. For example, if a stationary background appeared for 550 frames in a row in a 25-fps video, it’s more reasonable for a computer to recognize it as a single frame lasting for 22 seconds before proceeding.

Moreover, even if it’s not a single frame, compressors are smart enough to know there’s a pattern. For instance, if a star fades in, it might make more sense only to save the star’s image, and the code in the video will instruct the computer to do the fade-in action to the star. This is like inserting effects in your video editor or a PowerPoint slideshow.

Lossy Compression

However, lossless compression sometimes isn’t enough, especially for large video files. That means lossy compression needs to come into play. Keep in mind that the file will lose some data, details, and quality, and they cannot be retrieved after the compression.

Will the application delete random slices of data? No. If it’s truly random from the file, it might even delete the metadata, rendering the file unreadable. Therefore, the bits are removed so that the user experience is the least hindered. The more parts the app removes, the more significant the quality change is.

For example, if there are similar pixels in an image, they will probably be merged when it encounters lossy compression. They use some algorithms to determine which frames to remove or merge to minimize the effect on quality.

Conclusion

So, here’s a general article on three simple algorithms of data compression. We’ve also mentioned lossless and lossy compression and how they are different. There’s more to learn! Looking for a starting point? Take a look at the resources used in this article.

References and Credits

  1. (2018, November 21). Lossy vs Lossless Compression – KeyCDN Support. Retrieved March 6, 2021, from https://www.keycdn.com/support/lossy-vs-lossless
  2. CrashCourse. (2017, July 27). Compression: Crash Course Computer Science #21 – YouTube. Retrieved March 6, 2021, from https://www.youtube.com/watch?v=OtDxDvCpPL4
  3. Anthony Heddings. (2018, August 14). How Does File Compression Work?. Retrieved March 6, 2021, from https://www.howtogeek.com/362339/how-does-file-compression-work/
  4. Ben Stegner. (2019, July 26). How Does File Compression Work? Retrieved March 6, 2021, from https://www.makeuseof.com/tag/how-does-file-compression-work/
  5. (2020, November 20). Image File Size Calculator. Retrieved March 6, 2021, from https://www.omnicalculator.com/other/image-file-size

Related Posts

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.