filesdataFormats and data

04 / Compression

Compress, collect or preserve quality?

Archives, containers and compression solve different problems. Decide what you can afford to lose before choosing a format.

Lossless concerns the contents

Lossless compression lets you recover the original data from the compressed representation. It is a natural choice for text, tables, programs and master copies where every byte matters. ZIP and gzip normally apply such methods to file contents.

PNG is also lossless, but saving a PNG from any arbitrary source does not restore the original. If the source already underwent JPEG compression, a PNG will preserve the current pixels and artefacts. Image processing before saving is a separate change.

Lossy means a trade-off

Lossy compression discards some information to reduce size. It often suits photographs, sound and video intended for viewing or listening. Quality depends on the codec, settings, source material and number of repeated conversions.

Retain an editable source separately and produce compact versions as exports. Increasing the bitrate of an already damaged file will not restore detail. If you only need a trim, find out whether the tool can do it without re-encoding; precise frame boundaries sometimes require a new encode.

Compare like with like

MaterialPractical choiceCheck
Text and tablesZIP for a collection, gzip for a streamBytes and hashes after extraction
Diagram with textSVG or PNGReadability, size, SVG safety
Website photographJPEG or WebP exportEdges and fine-detail artefacts
Video for viewingA container with a supported codecMotion, sound and playback

Compare versions from the same source at the same target dimensions. A reduction percentage without the original and settings tells you little. Text may shrink substantially while a JPEG inside ZIP barely changes.

An archive is not a backup

An archive collects a set. A backup lets you recover it after losing the main copy. A ZIP beside the sources on the same failed disk does not solve the second problem. Encryption is not an automatic consequence of packing files either.

Before storage, inspect the contents and extract into an empty directory. Compare the inventory and open the result. For unfamiliar archives, first consider expanded size, nested archives and paths. Do not automatically agree to overwrite existing files.

A short decision rule

Need identical bytes? Use lossless compression. Need convenient viewing? A checked lossy export may suit. Need a collection? Use a container. Need preservation? Keep a separate copy and test restoration.