Code compression: what is it?

Print anything with Printful



Code compression reduces file sizes by using algorithms to make a smaller piece of code represent a larger piece. Lossy compression discards some data, while lossless compression retains it uncompressed. Compressed files must be decompressed before use.

Computer code can be thought of as the DNA of the digital world: the raw lines of data that make up all digital programs, graphics files, and music. The larger and more complex the file or application, the more code it contains. Given the limited limitations of hard drives and other types of data storage, code compression is often used to temporarily reduce file sizes. It works by using special algorithms to make a smaller piece of code represent a larger piece. Data can be compressed and uncompressed this way, as long as a compression program knows the correct algorithm to unlock it.

Most people who know how to use a computer are at least somewhat familiar with how data is stored, in terms of kilobytes, megabytes, gigabytes, and so on. What they may not understand is the relationship between these units of measurement and the actual words, graphics, music and programs they manipulate on the screen. A single byte represents a single text character and is itself made up of eight smaller units known as bits. Bits are the raw components of digital information, and the way they’re arranged creates different letters of the alphabet, numbers, or other types of characters.

A code compression program takes the bits and bytes that make up a given file and encodes them so that one or two characters in the compressed version represent a larger number than the original. The two main types of code compression are known as lossy and lossless. Lossy compression can be used in cases where some data loss is acceptable, such as music files where some frequencies are not needed. Basically, a lossy algorithm counts the number of times a given section of data is reused in a file and generates a smaller piece of code that calculates that number. Larger compression can usually be achieved using this method, and the MP3 format is an example of this type of compressed file.

The basic functional difference between lossy and lossless compression is that with lossy compression, data that cannot be compressed is discarded, while lossless compression keeps it, uncompressed. This leads to larger compressed file sizes, but retains the quality of the original file. Text documents and other similar files, where information cannot be lost, should be compressed this way.

In general, a compressed file cannot be used or manipulated unless it is first decompressed. Compression is a temporary state, thus mostly used for archiving or transmission purposes. However, this does not extend to compressed music and video files, for which there are programs capable of decoding on the fly, during playback.




Protect your devices with Threat Protection by NordVPN


Skip to content