Lossless compression
CompressionLossless compression reduces an image’s file size while guaranteeing that decompression reproduces the exact original pixel values, bit-for-bit. It relies on modelling and entropy coding rather than quantisation, so repeated encode/decode cycles are idempotent and introduce no generation loss. In web performance and SEO contexts, it is most valuable for graphics, UI assets, and source archives where perfect fidelity matters. It is distinct from “visually lossless” or “near‑lossless” approaches that permit small, controlled deviations to achieve greater size reductions.
Core mechanisms
Lossless image codecs reduce redundancy without altering the underlying pixel values. They combine predictors that transform pixels into more compressible residuals with entropy coding that assigns shorter codes to frequent symbols. Common building blocks include dictionary-based schemes (LZ77/LZ78/LZW), run-length encoding for repeated values, and context-adaptive Huffman or arithmetic coding. By modelling spatial correlation and colour channel relationships, these codecs lower entropy while keeping the reconstruction exact.
Format-specific pipelines illustrate this pattern. PNG applies per-scanline filters (Sub, Up, Average, Paeth) to predict each pixel from its neighbours, then compresses the filtered data with DEFLATE. WebP lossless uses colour caches, transforms, and an LZ77–Huffman backend. AVIF and HEIF can operate in a reversible mode where transform and prediction steps are invertible, producing bit-identical output. Across these designs, the key property is reversibility of each stage so the decoder reconstructs the original pixels exactly.
Benefits
The primary advantage is perfect fidelity: edges, text, and brand colours remain exact, which matters for logos, UI chrome, screenshots, technical diagrams, and assets reused across media. Because the process is reversible, lossless originals are ideal for editing pipelines; any downstream crops, resizes, or colour adjustments start from pristine data and avoid generation loss. On the web, this consistency reduces visual artefacts that can undermine perceived quality, especially on high‑DPI displays where minor distortions become more obvious.
Lossless compression also improves storage and caching efficiency versus uncompressed sources (for example, PNG versus BMP or TIFF without compression). For appropriate content types—flat colours, sharp boundaries, limited palettes—lossless formats can be very compact, supporting fast delivery without sacrificing brand accuracy. However, the benefit is context‑dependent: for photographic scenes, purely lossless images are usually much larger than high‑quality lossy alternatives, so the performance uplift hinges on matching the approach to the asset’s visual characteristics and usage.
Definition and scope
In imaging, “lossless” strictly refers to pixel data after decoding. If two files decode to identical pixel arrays—same colour values per channel, per pixel—they are losslessly equivalent even if their container structure, metadata, or compression parameters differ. This scope is narrower than the entire file; stripping metadata (EXIF, XMP) may reduce bytes without changing pixels, which is still lossless in the pixel sense, though not information‑preserving with respect to ancillary data. Conversely, changing colour depth or subsampling alters the pixel array and is inherently lossy.
Some formats are always lossless for raster data (PNG, GIF), while others offer explicit lossless modes (WebP lossless, AVIF lossless, JPEG 2000 lossless, JPEG‑LS). Reversible processing also depends on preserving channel layout (e.g., avoiding chroma subsampling) and bit depth. A workflow can be pixel‑lossless yet still alter the file in other ways—reordering chunks, normalising palette entries, or recomputing checksums—without affecting the decoded image. When precision matters, define whether “lossless” is being applied to pixels, metadata, or both.
Conceptual difference
Lossless compression exploits statistical redundancy, while lossy compression also removes perceptually less important information to reach much lower bitrates. Lossy codecs use quantisation and psychovisual models to approximate the image, trading exactness for size. This means repeated lossy re-encodes accumulate “generation loss,” whereas lossless re-encodes are idempotent—decoding and re‑encoding with the same settings yields the same pixels every time. In practice, the decision is a trade‑off between byte budget and fidelity requirements across the asset lifecycle.
Terms like “visually lossless” or “near‑lossless” describe lossy settings that are hard to distinguish by eye or that constrain the per‑pixel error. These are valuable for performance when perfect reconstruction is unnecessary, but they are not pixel‑exact. If verification is required, integrity can be tested with pixel hashes or by computing PSNR/SSIM against the original—true lossless produces infinite PSNR and SSIM of 1.0 because the decoded pixels match exactly.
Common formats
Several web‑relevant formats support lossless compression either by design or as a selectable mode. Their efficiency varies with content, encoder quality, and tuning. Browser support is strong for PNG, GIF, WebP, and AVIF; TIFF and JPEG‑LS are common in imaging workflows but not for direct delivery on the public web. The notes below outline typical use cases rather than strict rules, as results depend on images and settings.
- PNG (DEFLATE, filters): universal support; excels on graphics, UI, and transparency; large for photos.
- WebP lossless: typically smaller than PNG for many assets; supports alpha; broad modern support.
- AVIF lossless: can beat PNG size on some content; slower to encode/ decode; supports 10/12‑bit and HDR.
- GIF (LZW): legacy palette‑based; acceptable for simple graphics and animations; limited colour depth (8‑bit).
- TIFF (LZW/Deflate): archival or production workflows; not typically served directly on the web.
- JPEG‑LS and JPEG 2000 lossless: efficient for medical/scientific imaging; web support varies by browser.
Implementation notes
Encoder choice and options matter. For PNG, tools such as oxipng, zopflipng, and pngcrush explore filter strategies and DEFLATE parameters to minimise size without changing pixels. For WebP, use cwebp with -lossless and consider -m (method) and -q (quality in lossless context influences effort, not quantisation). For AVIF, encoders like avifenc provide --lossless flags; keep an eye on bit depth and chroma settings to avoid unintended conversions. Avoid colour profile changes or downsampling during pipeline steps intended to be lossless.
Verification is straightforward: decode both source and output to raw pixels and compare hashes; any difference indicates non‑lossless processing. In practice, also validate alpha premultiplication, colour management (ICC profiles, gamma), and metadata expectations. Typical outcomes: on photographic images, PNG can be 3–10× larger than a good lossy JPEG/WebP; WebP lossless tends to be 10–30% smaller than optimised PNG on many graphics; AVIF lossless can reduce a further 10–30% on some assets but may increase CPU cost. Results vary with content and encoder versions.
Comparisons
Lossless vs lossy for photos
For natural scenes, lossy codecs (JPEG, WebP, AVIF) exploit psychovisual tolerance to remove detail with minimal perceived impact, achieving far smaller files. Pure lossless on the same content usually produces substantially larger outputs and slower delivery. A pragmatic approach is to store masters in lossless formats for editing safety but publish lossy derivatives tuned to target devices and budgets. Reserve lossless delivery for cases where artefacts are unacceptable or where the image is inherently compressible (e.g., simple UI captures).
Lossless vs lossy for graphics and UI
For line art, icons, and text‑heavy assets, lossless often wins on both fidelity and size. PNG or WebP lossless typically preserve crisp edges and can beat lossy alternatives that introduce ringing or colour bleed. Vectors (SVG) avoid raster artefacts entirely and compress well via gzip, but when raster delivery is required—for example, for complex effects or broad compatibility—lossless raster formats remain a safe choice, especially where brand colours and sharpness are non‑negotiable.
FAQs
Is PNG always lossless?
Yes—PNG’s compression pipeline is reversible, so decoded pixels match the source exactly. However, operations such as reducing bit depth, converting colour spaces, or changing from truecolour to indexed palette are lossy transformations. Ensure your tooling avoids these conversions if pixel‑perfect output is required.
Does removing metadata break losslessness?
Not for pixels. Lossless, in this context, concerns the decoded image data. Stripping EXIF/XMP reduces bytes without changing pixel values, which is pixel‑lossless but not information‑preserving overall. Decide case‑by‑case whether metadata is required for your analytics, licensing, or colour management workflow.
How can I verify that an image was compressed losslessly?
Decode both the original and the candidate file to raw pixels and compare checksums. Identical hashes imply lossless equivalence. Metric‑wise, PSNR will be infinite and SSIM equals 1 when comparing a truly lossless result to its source. Visual inspection alone is insufficient because near‑lossless differences can be imperceptible yet still non‑zero.
Is lossless better for SEO and Core Web Vitals?
Not inherently. Search and Core Web Vitals reward faster loading and stable rendering. If lossless files are larger than suitable lossy alternatives, they may hurt LCP and bandwidth usage. Use lossless where fidelity is critical or sizes are competitive; otherwise, prefer well‑tuned lossy encodes for photos to balance quality and performance.
Is SVG considered lossless?
SVG is vector, not raster. It defines graphics as shapes and text rather than pixels, so there is no “compression loss” when scaling or editing. When transferred over the network, SVG is often gzipped, which is a lossless text compression method. Once rasterised to pixels (e.g., when exporting to PNG), losslessness depends on the target raster format and pipeline settings.
Synonyms
Learn More
Explore OPT-IMG's image optimization tools to enhance your workflow and get better results.