Lossy vs Lossless Compression
Also known as: Reversible vs irreversible compression
What Is the Difference Between Lossy and Lossless Compression?
Lossless compression shrinks a file so that decoding it rebuilds the original exactly, bit for bit. It works because real images, sound and video repeat themselves, and an encoder can describe those repeats in fewer bytes while leaving nothing out.
Lossy compression keeps an approximation instead, dropping the detail you are least likely to miss, which lets it reach far smaller files than any lossless method. Most of what a lossy codec does can be undone, and the loss comes mostly from quantization, which rounds values to coarser steps, as the video compression page shows frame by frame.
Lossless formats rebuild every bit
PNG compresses images with DEFLATE, and FLAC and ALAC do the same job for audio. GIF is lossless too, but it holds 256 colors at most, so a photo saved as GIF loses color before compression starts.
Lossy formats keep what you would notice
JPEG, the most widely used still-image format, is lossy. So are the audio codecs MP3 and AAC, and so are the codecs that deliver video, such as H.264. They trade exactness for files far smaller than a lossless copy. By default, most JPEG encoders also store one color sample for every four pixels, a step called chroma subsampling, since the eye picks up far less detail in color than in brightness.
WebP, AVIF and TIFF can be lossy or lossless
WebP has a lossy mode built on VP8 and a separate lossless mode, and AVIF, JPEG XL and TIFF can also store an image either way. The file extension alone doesn’t tell you which mode a file used, but its header does, as the checker on WebP vs PNG shows.
What Happens When You Save a Lossy File Again?
Opening a JPEG and saving it decodes the image and encodes it a second time, so the new file carries the first save’s loss plus whatever the second encode adds. Wikipedia calls this generation loss and shows a JPEG turned 90 degrees and saved up to 2,000 times, and social platforms add a round of their own when they re-encode uploaded images.
Edits between saves make it worse. A new quality setting switches JPEG to different quantization steps, cropping off the grid of blocks the encoder works on shifts those blocks, and turning the image causes similar damage. Tools such as jpegtran crop, rotate and flip a JPEG by rearranging its compressed data, without fully decoding it, so those edits add no loss.
Save an image 100 times
Each save decodes the last one and encodes it again, as an editor does when you open a file and save it. Turning the image a quarter turn before each save adds an edit in between.
- Average change per color value
- Pixels that changed
The panels enlarge the middle of the image; black in the difference means unchanged. Your browser does the encoding, so the numbers vary from one browser to the next, and nothing is uploaded.
Which Video Codecs Are Lossless?
The codecs that stream video, play it on phones and carry it to social platforms are lossy. Lossless video lives in archives and editing workflows, where a file many times the size of its delivery copy is worth keeping.
Delivery codecs are lossy
ProRes is visually lossless, which is still lossy
Apple describes ProRes 422 HQ as visually lossless, and Wikipedia lists ProRes among the lossy codecs that cause generation loss. The label means you can’t see the loss after one encode, not that nothing was lost.
FFV1 keeps every frame exact
FFV1 comes from the FFmpeg project, and the IETF published it as RFC 9043. It compresses each frame on its own and losslessly, and FFV1 in Matroska is one of the formats the Library of Congress prefers when it preserves video.
When Should You Use Lossy or Lossless?
Keep anything you will edit, print or archive lossless, and compress lossily once, for delivery. A print storefront, for example, keeps a customer’s uploaded logo as PNG rather than JPG, shows product previews as lossy WebP and sends the print PDF with its image quality left at full.
| Pick | Why | |
|---|---|---|
| Logos, screenshots and type | PNG, or WebP at quality 1.0 | Lossy artifacts show as blur and colored fringes around text and sharp edges |
| Photos on web pages | JPEG or lossy WebP | Photos usually tolerate lossy compression, since the dropped detail is hard to see |
| Anything with transparent areas | PNG or WebP | JPEG has no alpha channel; WebP keeps one in both modes |
| Files you will edit again | A lossless format until the last save | An edit followed by a lossy save adds new loss on top of the old |
| Color lookup tables (LUTs) | PNG | JPEG artifacts turn into visible color banding once the filter is applied |
| Print PDFs | Full image quality | Images that have to be rasterized stay lossless |
| Video for streaming and social | H.264, H.265, VP9 or AV1 | Players and platforms expect lossy delivery codecs |
| Video archive masters | FFV1 in MKV, or ProRes in MOV when visually lossless is enough | The Library of Congress prefers both for keeping video |
| Audio masters | WAV or FLAC | Both keep every sample of the recording |
How Lossy and Lossless Export Works in CE.SDK
Every PNG, JPEG or WebP export comes with its own compression setting, so your app decides file by file whether the result is lossless. The same goes for video editing in CE.SDK, where the bitrate decides how much detail an MP4 or WebM keeps.
PNG exports keep every pixel
Levels 0 to 9 of pngCompressionLevel, 5 by default, only change how small the file gets and how long encoding takes. The docs say quality is not affected at any level.
JPEG quality trades detail for size
jpegQuality accepts anything above 0 up to 1, with 0.9 as the default. Lower values make smaller files with more visible artifacts, and transparent areas come out on a solid background.
WebP turns lossless at quality 1.0
Set webpQuality to 1.0 and WebP encodes losslessly, which the docs say usually beats PNG on file size. Any value below 1.0 makes the export lossy.
PDF exports encode rasterized images losslessly
High compatibility mode is on by default and rasterizes each bitmap image of a PDF export at the scene’s DPI setting, storing the result losslessly unless your app sets pdfImageQuality below 1.0. Switch the mode off and CE.SDK embeds unmodified JPEG photos as they are, without rasterizing them.
Video detail follows the bitrate
MP4 exports hold H.264 or H.265, and WebM exports VP8, VP9 or AV1. When the export runs in a browser, its default bitrate is left to the encoder, which the docs warn may pick a very high, near-lossless rate, so set one when file size matters.
The sound in a video export is lossy too
An MP4 export carries its audio as AAC, a lossy codec. Where the browser can’t write AAC, Firefox for one, the MP4 gets Opus audio instead, which drops detail as well, and WebM exports use Opus every time.
// A logo with sharp edges and transparency: lossless WebP.
const logo = await engine.block.export(logoBlock, {
mimeType: 'image/webp',
webpQuality: 1.0
});
// A product photo for the storefront: JPEG at 80% quality.
const photo = await engine.block.export(photoBlock, {
mimeType: 'image/jpeg',
jpegQuality: 0.8
}); FAQs
Yes. PNG compresses with DEFLATE, which rebuilds every pixel when the file is opened, so its compression level changes only the file size and how long encoding takes.
No. The detail the JPEG encoder threw away is gone, so the PNG stores the decoded JPEG with its artifacts, usually in a larger file. Converting does stop the loss from growing, since saving that PNG again changes nothing.
Both. WebP has a lossy mode based on VP8 and a separate lossless mode, and either one can keep transparency. The encoder settings decide which mode a file uses when it is saved.
MP4 is a container, so it depends on the streams inside. Its usual video codecs, H.264, H.265 and AV1, are lossy, and its audio is generally lossy AAC, with MPEG-4 ALS as the lossless option the Library of Congress names.
It describes lossy compression whose loss you cannot see at normal viewing, as Apple says of ProRes 422 HQ. The data is still approximated, so encoding the file again and again can make the loss visible.
Links
Documentation and references for this concept.
Video Editor SDK
Give your users a browser video editor that exports MP4 or WebM at the bitrate you choose.
Compression guide
Set the PNG compression level and the JPEG and WebP quality for each export.
Export to WebP
Export WebP losslessly at quality 1.0, or lossily below it for smaller files.
Related Terms
PNG vs. JPG
Two raster image formats that compress differently. PNG is lossless and can be transparent, while JPG discards some deta…
Video Compression
Making a video file smaller by storing a whole frame only now and then, keeping just the changes for the frames in betwe…
Bitrate
How much data a video or audio stream holds per second, given in kbps or Mbps. An encoder treats it as a target that tra…
WebP vs. PNG
PNG and WebP both keep transparency. PNG is always lossless and stores up to 16 bits per channel, while a WebP file is l…



