How Image Compression Works
Image compression reduces the amount of data required to store or transfer an image. It can do this without changing the decoded pixels at all, or it can discard some visual information in exchange for a smaller file.
This is why “compress an image” can mean different things depending on the format and encoder. A PNG can be compressed losslessly. A JPEG typically uses lossy compression. WebP can support both lossless and lossy modes.
The practical goal is not simply to create the smallest possible file. It is to reduce unnecessary data while preserving enough visual quality for the image’s intended use.
File size, dimensions, and visual quality are different concepts
These three ideas are often confused.
Pixel dimensions describe the width and height of the image, such as 2400 × 1600 pixels.
File size describes how much storage the encoded file occupies, such as 850 KB or 4 MB.
Visual quality describes how closely the result matches what a viewer needs or expects.
You can reduce file size without changing dimensions by compressing more aggressively. You can also reduce file size by resizing the image to fewer pixels. These are separate operations.
A 5000-pixel-wide photograph encoded efficiently can still be unnecessarily large if the website only displays it at 1200 pixels. In that case, resizing may be the more effective optimization.
Conversely, a small image can still be badly compressed if the encoder has introduced visible artifacts.
Lossless compression
Lossless compression reduces file size while allowing the original encoded pixel values to be reconstructed.
It works by finding patterns, repeated data, and more efficient ways to represent the same information.
PNG is a familiar example of a format that uses lossless image compression. Lossless WebP is another.
Lossless compression is useful when exact pixels matter, when repeated editing is expected, or when the image contains graphics, text, transparency, or hard edges that should not be damaged by lossy artifacts.
The limitation is that lossless compression cannot discard visual detail. A complicated photograph may therefore remain relatively large.
The phrase “lossless” does not mean “small.” It means the compression does not rely on throwing away the original pixel information represented by that encoding.
Lossy compression
Lossy compression reduces file size by discarding information that the encoder estimates can be removed with acceptable visual impact.
JPEG is the classic example. Lossy WebP can use a similar overall trade-off, although the internal codec differs.
At moderate quality levels, the removed information may be difficult to notice at normal viewing size. At aggressive settings, artifacts become obvious.
Common lossy artifacts include:
- block-like patterns;
- ringing around sharp edges;
- smeared texture;
- loss of fine detail;
- gradients becoming less smooth;
- color changes;
- text and line art losing crispness.
The ideal level depends on the image. A photograph of clouds may tolerate compression differently from a screenshot containing small text.
What a quality slider actually does
A quality slider usually controls an encoder trade-off between fidelity and file size. It is not a universal percentage of “original quality.”
A value of 80 in one encoder is not guaranteed to produce the same result as 80 in another. Even within the same encoder, two images at the same quality can have very different sizes.
Complex texture, noise, foliage, hair, fine patterns, and grain are difficult to compress efficiently. Large smooth areas are often easier.
This is why a good compressor should show the resulting file size and allow visual inspection rather than promising that one quality value is ideal for every image.
If a moderate setting looks good and the file is small enough, there is no reason to lower quality further simply to achieve a larger percentage saving.
Why resizing is often more powerful than compression
An image with twice the width and twice the height contains four times as many pixels.
That means pixel dimensions have a major effect on the amount of data an encoder must represent.
Suppose a camera photo is 6000 × 4000 pixels, or 24 megapixels. If a webpage only needs an image around 1500 pixels wide, reducing the dimensions can remove a large amount of unnecessary pixel data before compression even begins.
This often produces a cleaner result than retaining the huge original and using extremely aggressive compression.
For web delivery, a practical optimization workflow is frequently:
resize first → choose output format → apply reasonable compression → inspect result.
That is the logic behind a workflow such as Prepare for Web.
Why screenshots behave differently from photographs
Photographs contain natural texture and continuous tones. Screenshots contain text, icons, flat colors, thin lines, and sharp boundaries.
JPEG compression is optimized around properties that work well for photographs, but the same process can create visible artifacts around interface text and graphics.
A PNG screenshot can sometimes remain relatively compact because large flat regions compress well losslessly.
A full-screen photograph saved as PNG, by contrast, may be much larger.
Therefore “PNG is larger than JPEG” is not a universal rule in every possible image. Format efficiency depends on the content.
The practical rule is to match the codec to the image type and destination.
Compression and transparency
Transparency adds another dimension to the problem.
PNG can preserve an alpha channel losslessly. WebP can also support transparency. JPEG cannot.
If a transparent image is converted to JPEG, transparent pixels have to be replaced with a background color.
For a reusable logo or cutout, that may be undesirable. For an image that will always appear on white, flattening transparency can be acceptable and may permit more efficient photographic compression.
The decision should be driven by how the image will be used, not just file size.
Repeated compression can accumulate damage
A common mistake is to repeatedly save a lossy image.
If a JPEG is opened, edited, and re-encoded many times, each generation can discard additional information. The artifacts from one generation become part of the input to the next.
This is why keeping a good master file is useful.
If you need multiple delivery versions, create them from the best available source rather than compressing one delivery copy into another.
The same principle applies to social media downloads and screenshots. A file that has already been re-encoded by another service may have less clean information than the original.
Metadata can contribute to file size
Image files can contain more than pixels.
EXIF, XMP, thumbnails, color information, comments, and application metadata can add data. In many photographs, metadata is not the dominant part of the file, but removing unnecessary metadata can still reduce some overhead and improve privacy.
Do not confuse metadata removal with image compression. They solve different problems.
Compression changes how image data is represented. Metadata cleaning removes supported auxiliary information.
A workflow can do both, but the reasons are different.
How to evaluate a compressed result
Do not judge only by the percentage saved.
Review:
- faces and skin detail;
- hair and fur;
- text;
- high-contrast edges;
- gradients;
- shadows;
- fine product details;
- repeated patterns.
Inspect at normal display size first. Then zoom in enough to find obvious artifacts.
If the image will be displayed at 800 pixels wide, a tiny artifact visible only at 500% zoom may not matter. If the image will be printed or cropped later, more detail may need to be preserved.
Also compare the result against the actual destination. An image for a thumbnail has different requirements from a full-width portfolio photograph.
Common compression mistakes
The first mistake is trying to solve oversized dimensions only with a low quality setting.
The second is assuming a smaller file is always better.
The third is applying JPEG compression to text-heavy screenshots without inspecting edge quality.
The fourth is converting between lossy formats repeatedly.
The fifth is publishing camera-resolution images when the layout never displays them anywhere near that size.
The sixth is comparing file sizes without checking that the images have the same dimensions and format.
A practical compression workflow
For a typical web image:
- Start with the best source.
- Determine the largest display size you actually need.
- Resize if the original is substantially larger.
- Choose a format appropriate to the image and transparency needs.
- Use a moderate quality level for lossy output.
- Inspect the result.
- Compare file size and visible quality.
- Reduce quality only if more savings are useful.
- Keep a higher-quality master separately.
prvkit’s Compress Image tool focuses on compression, while Resize Image changes dimensions and Prepare for Web combines several delivery-oriented choices. Keeping those concepts distinct helps you make intentional decisions rather than treating “compression” as a single magic operation.
Good image compression is a balance. The smallest file is not automatically the best result. The useful result is the one that removes data the destination does not need while preserving the visual information the viewer does.