A 12-megapixel photo is 4,032 by 3,024 points. If each point stored its three values of red, green and blue at eight bits apiece, the file would weigh 36.6 megabytes. The camera, however, writes between three and four. Inside that order-of-magnitude gap sit four decisions that are not magic: they are applied mathematics built on a very precise idea of what the human eye is willing to notice.
First, the colour is not where you think
The sensor does not see colours. It sees light. Most consumer sensors carry a Bayer filter in front of them: a grid where two of every four photodiodes let green through, one lets red and one blue. It is called a mosaic because that is what it produces, an image in which each pixel knows only one channel. The processor rebuilds the other two by interpolating from neighbours — a step called demosaicing — and out of that comes the full RGB triad.
Before that, each photodiode has delivered a 12- or 14-bit reading proportional to the photons received: a linear relationship with light. The eye, by contrast, responds roughly logarithmically. So the processor applies a transfer curve — gamma — that spreads the 256 eight-bit levels where sight distinguishes the most nuance, in shadows and midtones, and leaves fewer where it does not, in the highlights. That distribution is the first place information is lost, and nobody perceives it as loss.
Second: light is separated from colour
The eye has two different systems. Cones, which provide detail and colour vision, are concentrated in the fovea and are scarce outside it; rods, far more numerous, do not distinguish colour but do detect contrast and movement. Translated into numbers: we see with high resolution in luminance and with considerably less in chrominance.
JPEG exploits exactly that. It converts every RGB pixel to YCbCr: a luminance component Y and two chrominance components, Cb and Cr, which are the blue and red differences with respect to luminance. The usual transform is the BT.601 one, with fixed coefficients: Y = 0.299·R + 0.587·G + 0.114·B. Nothing is lost yet; it is a change of basis, like describing the same point along other axes.
The loss arrives with chroma subsampling. In the most common mode, 4:2:0, for every 2×2 block of pixels the encoder keeps all four Y samples but only one Cb and one Cr, taken from the block average. That is six values instead of twelve: half the file disappears before any compression happens. Does it show? In a landscape, almost never. On a red edge against a white background — a sign, coloured text — the typical colour bleed appears, that two-pixel pink fringe that gives JPEG away.
Third: each block becomes frequencies
From here the image is split into 8×8 pixel blocks per channel: 64 samples. On each block the encoder applies the discrete cosine transform, the DCT. The DCT does not compress: it reorganises. It turns the 64 brightness samples into 64 coefficients representing spatial frequency patterns, from a flat base up to a chequerboard of eight cycles per block.
The first coefficient, the DC, is the average of the whole block. The other 63, the AC ones, describe how much of each pattern is present. The trick is that in natural photography the energy concentrates in the low coefficients: most blocks are smooth surfaces with a little texture, so high-frequency coefficients come out small, almost always near zero.
Fourth: quantising is deciding what to throw away
This is where the real loss lives, and not before. Each coefficient is divided by the corresponding value in a quantisation table and rounded to the nearest integer. A typical table holds small numbers in the low-frequency corner (1, 2, 3) and large numbers in the high one (30, 60, 99). Dividing by 60 and rounding turns almost any fine detail into an exact zero.
The quality factor you adjust on export is nothing more than a multiplier on that table. At quality 90 the tables scale down and more coefficients survive; at 50 they double and the block is left with its average. Then the coefficients are read in zigzag — from the low-frequency corner to the high one — so that zeros group into long runs, and those runs are encoded with variable length: a short Huffman code for the repeated zero, longer codes for rare values. It is lossless compression on top of data that has already been mutilated with loss.
The marks left on the photo
The system leaves recognisable traces. The 8×8 grid shows up in skies and gradients when compression is heavy: those staircases of square edges appearing in areas that should be continuous. Around high-contrast edges the mosquito noise appears, a ripple of pixels oscillating next to the line; it is the Gibbs phenomenon caused by cutting high frequencies abruptly. And colour shifts sideways because of subsampling, especially in saturated reds.
It also explains something almost nobody allows for: recompressing hurts. Every save quantises coefficients that were already quantised, and the errors pile up generation after generation. And no, a smaller file on re-save is not an improvement: it is the same image with another layer of loss on top.
That is why some images should never be JPEG. A logo, a screenshot, a chart with text: content with hard edges and flat colours, the exact opposite of what the DCT expects. There the mosquito noise attacks the letters, and PNG — lossless compression based on prediction and the zlib library — weighs less and looks better.
What comes behind
JPEG dates from 1992 and remains the most widespread format on the planet for an unromantic reason: everything understands it, from a 1998 printer to the browser on your phone. Its replacements have spent years trying with more tools: HEIC and AVIF borrow techniques from video, predict blocks from their neighbours and store less residual; JPEG XL adds a mode with its own transform and one striking feature, the ability to recompress an old JPEG without extra loss, recovering the original coefficients so they can be stored again more efficiently.
While that gets settled, the photo you have just taken has already made the four decisions without asking you: it interpolated the colour the sensor never saw, threw away half the chrominance, turned each block into 64 frequencies and rounded to zero everything below the threshold of the perceptible. And you look at it on the screen and see it whole.






