Published on

Compression: Lossy vs Lossless

Authors
  • avatar
    Name
    Kiet
    Twitter

Lossy

This type of compression reduces file size by permanently removing some of the original data.

An algorithm scans image files and reduces their size by removing information considered less important or undetectable to the human eye.

Used when you need to balance between three factors:

• Storage requirements • Loading times (e.g., images on the web) • Quality

Example: JPEG (JPG), MP3, MP4.

With JPEG, the image is compressed when it is saved, and data is lost. If you open a JPEG and re-save it, more data will be lost each time.

Lossless

This type of compression reduces file size by removing unnecessary metadata and can decompress back to its original form.

Examples: PNG, WAV, HEVC.

An interesting example of this compression is GIF. GIF is lossless, but many people misunderstand and think it’s lossy. I think this confusion often arises when converting an image with rich color depth (like a PNG or a JPEG with millions of colors) into a GIF, which is limited to a palette of 256 colors. This process is lossy because color information is discarded to fit within the GIF’s color limitation. Even though the GIF format is lossless in terms of compression, color quantization (the process of reducing a large number of colors to fit within the 256-color limit) can result in a loss of detail or color accuracy.