Open an HDR photo on a phone that supports it, and the sky looks genuinely brighter than the rest of the screen — not just more contrasty, but like there's more light coming from it. Open that same file on an older device, and you just see a normal, perfectly reasonable photo. Both of those are the same file. The mechanism that makes that possible, in most cases you'll actually run into, is called a gain map.
Two images in one file
A gain-map HDR file isn't one image with extra-bright pixels. It's two images bundled together: a normal, standard-dynamic-range (SDR) photo — the primary — and a second, smaller grayscale image — the gain map — where each pixel says how much brighter the corresponding pixel in the primary should get, on a display that can show it.
White in the gain map means "boost this pixel as much as this photo ever needs." Black means "leave it alone." Everything in between is a partial boost. A handful of extra numbers in the file's metadata (things like how much the brightest boost actually corresponds to, in real terms) tell a decoder exactly how to turn that grayscale map into real extra brightness.
Why bother with two images instead of one?
Backward compatibility. Any app, browser, or device that has never heard of gain maps can still open the file — it just reads the primary image and shows a normal SDR photo. Nothing breaks, nothing looks wrong. Only software that specifically knows to look for the gain map recombines the two and shows you the boosted version. That's a meaningfully different bet than formats that require a decoder to understand HDR at all just to render the file correctly.
How the boost actually gets computed
For each pixel, an encoder compares how bright that pixel currently is (in the SDR primary) to how bright it's supposed to end up (the HDR target, based on the mapping mode and settings you choose). The ratio between those two — expressed as a log2 value, since brightness perception is roughly logarithmic — becomes that pixel's value in the gain map. A pixel that shouldn't change at all gets a gain of zero; a pixel that should hit the file's maximum boost gets the gain map's brightest value.
Where you've actually encountered this
Ultra HDR (Google's format, used by Android's camera and Google Photos), Adobe's Gain Map specification, and Apple's HDR photo pipeline are all variations on this same idea. If you've taken an HDR photo on a recent phone, it's very likely a gain-map file under the hood — see What is Ultra HDR? for the specific format most Android photos use.
Try it on a real file
Encode builds this exact kind of file from any photo you give it — primary image, computed gain map, and the metadata a decoder needs, all spliced into one real JPEG and round-trip validated before you can download it. Inspect reads any image you give it and tells you honestly whether it actually has a gain map embedded, rather than guessing from the filename or extension.
