In terms of the reversibility of the compression process, data compression may be classified as either lossy or lossless, depending on whether or not the process results in the loss (or preservation) of the original information. The two distinct classifications of algorithms each have their own set of advantages and disadvantages and specific uses.
Archiving of files using lossless compression
Lossless compression is a kind of data compression that eliminates redundant data by using statistical models to translate the input to a smaller output.
This allows the output to carry precisely all of the information featured by the input in fewer bytes. It also allows the work to be expanded to a 1:1 copy of the original data (restoring the actual content). This is essential for storing certain types of data, such as a software application or database.
Because of this, lossless compression algorithms are used for data backups and archive file formats used in general-purpose archive manager utilities like 7Z, RAR, and ZIP. These algorithms are utilized when an exact and reversible image of the original data must be saved. Examples of these scenarios include:
Some examples of lossless compression algorithms are Deflate (which is used for formats such as ZIP and GZ), BZip2 (which is used in the BZ2 format), PPMd (which is used for formats such as RAR and 7Z), and LZMA/LZMA2 (7Z/XZ format).
Lossless compression is totally reversible, meaning that a 1:1 duplicate of the original content input is kept in the smaller, more efficiently encoded output. As a result, it is often ideal for backup, file archiving, and other applications in which any loss of information is not acceptable.
Some graphic file formats, most notably PNG files and deflated TIFF, use lossless compression, which typically results in less compression but no image quality degradation after multiple cycles of modification and saving of the picture. Because of this, this kind of image format is suitable for use as intermediate save files for image editing tools. PNG files and deflated TIFF files are two examples of graphic file formats that use lossless compression.
Multimedia data compression specification for lossy compression
Lossy compression, on the other hand, works by locating the information that is either superfluous or less useful (as opposed to just deleting redundant data) and removing it.
The amount of information that must be compressed is effectively decreased, in contrast to the lossless compression.
The information or content loss is irreversible and depends on the algorithm's nature. It will likely occur each time the content is modified and saved to a lossy file format. For example, the loss of information or content occurs when editing a lossy jpeg image and saving it multiple times to intermediate work files.
The ratio achieved in this manner is improved, but only at the expense of turning lossy compression into an irreversible process. This is because lossy compression causes some of the information to be lost in the process, so it should only be used in situations where it is not intended to be possible to recreate the original content again.
Lossy compression is therefore not suitable for general-purpose file archiving (for example, losing a single byte of an executable file would cause it to stop working). Still, it works very well when loss, reducing less relevant information, is acceptable, as for graphic and multimedia files compression - for example, for MP3 losing audio information below the audibility threshold, or losing not visible details in JPEG images, or both in compressed video formats such as MPEG. Losing audio information below the audibility threshold (AVI, MKV, MPG, MP4...).
The algorithms for compression
Loss of information is detrimental to performing a 1:1 reversal of the algorithm (the data is lost forever). Still, it does not compromise the capability of end-users to receive information that is meaningful to them in the form of understandable audio, clear pictures, or videos.
Because of this, most standard lossy compression methods are often precisely tailored for the particular pattern of a specific form of multimedia data.
Because of this very same reason, certain types of files that have been compressed using lossy algorithms will not compress well (or at all) if added to archive files that have been compressed using general-purpose compression algorithms: files that have already been compressed compress poorly, if at all.
Since those compression schemes are lossy, however, professional editing work is typically done on non-compressed data (such as WAV audio or TIFF images) or data compressed in a lossless way (such as FLAC audio or PNG images) whenever it is feasible. This is done to ensure that saving the work in progress multiple times does not result in losing bits of information each time, leading to progressive quality degradation. Typically, the use of lossy compression is reserved for the final step of
Lossy vs lossless compression
Both lossy and lossless compression algorithms are so vastly diverse in their application areas that they cannot be compared head-to-head.
Lossless, fully reversible compression is the only option when the original content needs to be restored completely on decompression (binary files, raw data). However, when some degree of data loss is acceptable (for example, finalizing work on multimedia files such as mp3 audio, MPEG video, or jpeg graphics), the advantages of lossy compression in terms of speed and maximum compression ratio over lossless compression are generally so evident that lossy, nonreversible compression is the only option.