← Lab
ASTERXOR / Lab

Why two identical-sized images weigh so differently

The dimensions tell you how many pixels exist. The file size tells you something about how those pixels can be described.

Three equal-sized generated images: flat gold, smooth gradient and random RGB, shown as a side-by-side triptych.
These are locally generated test images, not photographs. Every source uses 8-bit RGB with the same dimensions and no added metadata.
LabASTERXOR / LEON LEUNG

Three images. Exactly 786,432 pixels each. PNG files from four thousand to more than two million bytes.

A flat gold field, a smooth gradient, and a cloud of random color share the same 1024 × 768 canvas. Save them with identical settings and the files diverge dramatically. The missing ingredient in “How big is this image?” is the structure of its contents, and what the format is allowed to discard.

The canvas has a size. Its description has a cost.
START WITH PIXELS

The one size dimensions can tell you

A 1024 × 768 image contains 786,432 pixels. With three eight-bit color channels, the raw RGB sample array occupies 2,359,296 bytes: one byte each for red, green, and blue at every location. That calculation is exact for this representation. It does not include a file header, a color profile, an alpha channel, or an application’s extra working memory.

The saved file is another representation of those samples. It may describe repeated patterns compactly, change how colors are encoded, or throw away information. Pixel dimensions therefore set an important baseline without determining the downloaded byte count. A file can be much smaller than its decoded samples, and an unhelpful input can even make a lossless file slightly larger.

LOSSLESS

Repetition gives PNG something to work with

PNG preserves the decoded pixel values in this experiment. Its filtering stage can turn predictable changes between neighbouring samples into easier-to-compress data, followed by lossless compression. A flat field offers abundant repetition. The gradient contains structure too, although small row-to-row changes and rounding make its encoded description less trivial than “fade from here to there.”

The measured PNG files were 4,025 bytes for the flat field, 102,469 for the gradient, and 2,363,424 for random RGB. All decoded exactly to their source arrays. The random image supplies little useful predictability, so its PNG is slightly larger than the raw RGB array after encoding overhead.

Grouped log-scale bars compare PNG and JPEG file sizes for flat color, a gradient, and random RGB.
FIG 01Actual file sizes, plotted on a logarithmic axis. One KiB is 1,024 bytes; the vertical gaps represent ratios rather than equal byte differences.
LOSSY

JPEG changes the bargain

The JPEG files were 12,917, 23,726, and 594,655 bytes at quality 85 with 4:2:0 chroma subsampling. JPEG is larger than PNG for the flat field here, while it is smaller for the other two images.

JPEG typically separates brightness-like information from color differences, reduces color resolution when subsampling is enabled, and quantizes transformed block coefficients. The decoded pixels need not match the originals. The enlarged random-color crop makes this visible: the bright, independent color specks become a different, more muted texture. Fewer bytes bought a changed image, not a free reduction in the cost of preserving every sample.

Side-by-side enlarged crops show vivid independent RGB pixels and the more muted JPEG reconstruction.
FIG 02The same 64 × 64 region before and after JPEG encoding, enlarged with nearest-neighbour display. This intentionally harsh input exposes changed color detail.
THE DIAL

Quality 85 does not mean 85 percent intact

An encoder’s quality setting controls a trade-off; it is not the percentage of original information retained or a promise about what a viewer will notice. On the random RGB source, increasing the tested setting from 25 to 95 grew the file from 190,431 to 922,548 bytes. The mean squared RGB error fell from about 4,962 to 3,487.

That error is simply the average squared difference between original and decoded channel values. It is useful for checking that samples changed, but it is not a perceptual verdict. Here chroma subsampling stayed at 4:2:0 even at quality 95, so raising the quality setting did not restore the source’s full color resolution. Other encoders and settings can behave differently.

Two line charts show JPEG size rising and mean squared RGB error falling as the quality setting increases.
FIG 03Five actual encodings of the same random input. The left chart shows file size in KiB; the right measures pixel error, not perceived quality.
THE CAVEAT

Looking right takes more than preserving numbers

A lossless round trip verifies sample values, not the entire viewing experience. A color profile tells a display system how those values should be interpreted. Metadata, orientation, transparency, bit depth, and a viewer’s color handling can also matter. These synthetic samples contain no added EXIF or ICC profile, so this experiment does not evaluate a color-managed photographic workflow.

Nor is random RGB a representative photograph. It is a useful stress case because neighbouring pixels intentionally tell you almost nothing about one another. A portrait, screenshot, scanned drawing, and noisy night scene have different structures. Their size and quality trade-offs should be judged on the actual content and destination rather than borrowed from this one chart.

IN PRACTICE

Ask what needs to survive

For a crisp diagram or interface capture, preserving edges, text, and transparency may matter more than shaving off the last few bytes. For a photograph, a carefully checked lossy export may be a sensible exchange.

Compare exports at the size people will actually view, inspect important detail, and measure the resulting files. Keep the original when repeated editing is likely. Resizing can reduce the number of samples; compression changes their description. Knowing which lever you are pulling makes “make it smaller” a much clearer request.

THE THOUGHT TO TAKE AWAY

A small file can be an elegant description, a good compromise, or a damaged image. Its byte count alone cannot tell you which.