30

Bit Depth, Channels, and Alpha

Under every color you have read about in this library is a far less glamorous truth: in a file, a color is just a handful of numbers. How many numbers, how many bits each, and what they mean - that is what decides whether a gradient is smooth or striped, whether an edge composites cleanly or fringes, and how big the file is. This is the interactive guide to how color actually lives in memory.

Digital · 35 4 Live Demos ~35 min read Color in memory
8-bit
256 levels per channel
16.7M
8-bit RGB colors
α
The fourth channel
10-bit
Banding fix / HDR
01

Color is just numbers

A digital image is a grid of pixels, and each pixel is a small set of numbers - typically red, green, blue, and often a fourth, alpha. The colorful physics and perception elsewhere in this library all collapse, at storage time, into integers like (220, 40, 40, 255). Everything practical about digital color - smoothness, transparency, file size, fidelity - comes down to three questions about those numbers: how many channels, how many bits each, and how they are interpreted.

Get those right and color "just works." Get them wrong and you meet the classic bugs: striped skies, muddy edges, posterized exports, and files ten times bigger than they need to be.

The three questions: (1) How many channels? RGB, RGBA, grayscale, or an indexed palette. (2) How many bits per channel? 1, 8, 10, 16, or float. (3) How are they interpreted? Straight or premultiplied alpha, linear or gamma-encoded, direct color or an index into a palette.
02

Bit depth and levels

Bit depth is how many bits store each channel, which fixes how many distinct levels that channel can take: 2bits. Eight bits give 256 levels per channel and 2563 ≈ 16.7 million RGB colors. Drop the bit depth and the steps between levels grow until they become visible as banding across a smooth gradient.

Interactive 01 · Bit depth

Crush the levels and watch a gradient band

The same smooth gradient quantized to the chosen bits per channel. At 8 bits it is smooth; lower it and the steps appear as bands. The readout shows the levels per channel and the total representable colors - the numbers behind the picture.

8 levels · 512 colors
03

Channels: splitting a pixel

A color image is really three (or four) grayscale images stacked together - one per channel. Each channel records how much of that primary is present at each pixel. Editors expose this directly: you can view, adjust, or swap a single channel, and "grayscale" is just the channels collapsed into one luminance image.

Interactive 02 · Channel splitter

See a scene one channel at a time

The full-color scene, then each channel shown alone as the intensity of that primary, and finally the luminance (perceptual grayscale). Notice how the red apple is bright in the red channel and dark in the others - a channel is a map of one primary.

Full RGB - all three channels combined.
04

Alpha and compositing

The fourth channel, alpha, does not store color at all - it stores opacity, how much of the pixel is "there." On its own it does nothing; it tells the compositor how to blend this layer over what is behind it, using the "over" operator. Alpha is what makes transparency, anti-aliased edges, and layered UI possible.

result = foreground × α + background × (1 − α) The "over" operator, applied per channel. α = 1 is fully opaque (you see only the foreground); α = 0 is fully transparent (you see only the background).
Interactive 03 · The over operator

Blend a layer over a background

A foreground color at the chosen opacity, composited over a background (the checkerboard shows true transparency). Drag alpha from 0 to 1 and watch the foreground fade in. The readout gives the exact composited color from the formula above.

over
Composited color over the solid background: #6A5FA8 · over the checkerboard you see the true alpha.
05

Premultiplied vs straight

There are two ways to store an RGBA pixel, and mixing them up is a classic source of ugly edges. With straight (unassociated) alpha, the RGB values are the true color and alpha is kept separate. With premultiplied (associated) alpha, the RGB values are already multiplied by alpha, so a 50%-opaque red is stored as half-strength red. Premultiplied is what compositors use internally because it makes filtering correct: when you scale, blur, or anti-alias an edge, premultiplied values interpolate without pulling in the color of fully transparent pixels.

Straight alpha
RGB is the real color; alpha stored separately. Intuitive for authoring and editing, but naive filtering bleeds transparent regions in.
Premultiplied alpha
RGB already scaled by alpha. The "over" operator simplifies and edges filter cleanly - the standard for rendering pipelines.
The fringe bug
Scaling a straight-alpha sprite with a black transparent border smears dark halos around the edges. Premultiply first to avoid it.
Know which you have
Importing premultiplied as straight (or vice versa) lightens or darkens semi-transparent areas. Match the interpretation to the data.
The tell: if exported PNGs show a dark or bright halo around soft edges where they meet a different background, you have a premultiplied/straight mismatch - or you composited in gamma space instead of linear (see the gamma article). Fix the alpha interpretation first.
06

Indexed color and quantization

Not every image stores full RGB per pixel. Indexed color (as in GIF and PNG-8) keeps a small palette of colors and stores, per pixel, just an index into it - a few bits instead of 24. The trade-off is quantization: every original color must snap to the nearest palette entry, so gradients posterize and detail is lost. Shrink the palette and watch the image collapse onto fewer and fewer colors.

Interactive 04 · Palette quantization

Map an image onto a small palette

The colorful source is reduced to a palette of the chosen size; every pixel snaps to its nearest palette color. The swatches below are the palette. Small palettes mean tiny files and heavy posterization - the GIF trade-off in one slider.

3 bits/px
07

Bit budgets: 8, 10, 16, float

How many bits you spend per channel is a budget against banding, editing headroom, and HDR. Eight bits is the web baseline and fine for final, gamma-encoded display images. But edit aggressively - big curves or exposure moves - and 8-bit steps get stretched into visible bands, which is why editing and HDR want more.

Depth Levels / channel Use for
8-bit 256 Final web/display images; SDR delivery. Bands under heavy edits.
10-bit 1,024 HDR video and smooth gradients; banding-free SDR on capable displays.
12-16-bit 4,096-65,536 RAW capture and editing masters - huge headroom for adjustments.
16/32-bit float continuous Linear-light compositing and HDR rendering; values can exceed 1.0.
The rule of thumb: capture and edit high (12-16-bit or float), deliver low (8-10-bit) once, at the end. Every aggressive edit in 8-bit throws away levels you cannot get back - work with headroom, then quantize last.
08

Practical guide

If you need… Use…
Transparency / soft edges An alpha channel (RGBA) - PNG or WebP, not JPEG.
Smooth gradients without banding 10-bit+ where possible, or add dithering at 8-bit.
Tiny files for flat graphics Indexed color (PNG-8 / GIF) with a tuned palette.
Editing headroom 16-bit (or RAW) masters; export to 8-bit only at the end.
Correct compositing Premultiplied alpha, blended in linear light.
HDR delivery 10-bit with a PQ/HLG transfer function (see the HDR article).
09

Pitfalls and gotchas

Editing in 8-bit
Heavy curves on 8-bit data band. Edit in 16-bit and flatten to 8-bit only for final export.
Premultiplied mismatch
Treating premultiplied data as straight (or vice versa) lightens or darkens semi-transparent pixels. Match the interpretation.
JPEG for transparency
JPEG has no alpha channel. Use PNG or WebP when you need transparency.
Over-shrinking a palette
Too few indexed colors posterizes photos badly. Use full color, or dither, for continuous-tone images.
Compositing in gamma space
Alpha blending on gamma-encoded values darkens edges. Composite in linear light, then encode.
Assuming 8-bit is "enough"
Fine for final SDR, not for masters or HDR. Match the bit budget to the job, not habit.
10

Test your understanding

Six questions on bit depth, channels, alpha, and indexed color. Instant feedback, no scores recorded - a wrong answer comes with a short explanation.

Quick check

Loading…
 
Question 1 of 6
11

Continue your journey

Storage sits beneath encoding, gradients, and HDR. The numbers reflect each article's position in the editorial roadmap.