Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 50 ยท Color

RGB, CMY and CMYK Color Models

Understand additive RGB and subtractive CMY/CMYK color, the RGB color cube, gamut and conversion code, with a live color mixer and overlap demos.

Every pixel on your screen is a mixture of just three lights. Every page in a printed book is a mixture of just a few inks. Yet both can show millions of colors, and the two systems work in opposite ways. A color model is a way to describe a color with numbers, and which model is right depends on the device: a monitor emits light, a printer absorbs it.

This lesson covers the three models every graphics programmer meets first. RGB is how screens and framebuffers store color. CMY and CMYK are how printing thinks about it. You will see why they are mirror images of each other, how to convert between them in code, and why a conversion never gives exactly the same color on paper.

Additive color: RGB

Your eye has three kinds of color receptors (cones), sensitive roughly to red, green and blue light. A display fools them by emitting three small lights per pixel and varying how bright each one is. Because light adds up, the model is called additive.

  • Red + green light looks yellow.
  • Green + blue light looks cyan.
  • Blue + red light looks magenta.
  • Red + green + blue at full strength looks white.
  • No light at all is black.

With 8 bits per channel, each of R, G and B is an integer from 0 to 255, so there are 256 x 256 x 256 = 16,777,216 combinations ("24-bit color", or "true color"). The frame buffers from Pixels, Resolution and the Framebuffer store exactly these triples (usually with a fourth alpha byte for transparency).

The color cube

If you treat (R, G, B) as coordinates, every color is a point in a cube. The corners are the eight "pure" colors, and the diagonal from black (0, 0, 0) to white (255, 255, 255) holds all the greys, where R = G = B.

flowchart LR
  K["Black<br/>(0,0,0)"] --- R["Red<br/>(255,0,0)"]
  K --- G["Green<br/>(0,255,0)"]
  K --- B["Blue<br/>(0,0,255)"]
  R --- Y["Yellow<br/>(255,255,0)"]
  G --- Y
  G --- C["Cyan<br/>(0,255,255)"]
  B --- C
  R --- M["Magenta<br/>(255,0,255)"]
  B --- M
  Y --- W["White<br/>(255,255,255)"]
  C --- W
  M --- W

The eight corners of the RGB cube and the edges that connect them.

Thinking in the cube helps with simple operations. Interpolating between two colors moves along a line inside the cube. Making a color brighter moves it toward white. Converting to grey projects it onto the diagonal.

Subtractive color: CMY

A printed page does not glow. Ink on white paper works by absorbing some of the light that falls on it and reflecting the rest. Each ink therefore subtracts light, and the model is called subtractive. The three standard inks are the complements of the RGB lights:

  • Cyan ink absorbs red (it reflects green and blue).
  • Magenta ink absorbs green.
  • Yellow ink absorbs blue.

Mixing inks removes more and more light: cyan + magenta gives blue, magenta + yellow gives red, yellow + cyan gives green, and all three together absorb nearly everything, giving a dark colour. Paper with no ink is white, the opposite of the additive case.

Because CMY is the complement of RGB, conversion with values in the range 0 to 1 is just a subtraction:

TEXT
C = 1 - R        R = 1 - C
M = 1 - G        G = 1 - M
Y = 1 - B        B = 1 - Y

Pure red (R = 1, G = 0, B = 0) becomes (C = 0, M = 1, Y = 1): "put magenta and yellow ink on the page and no cyan", which indeed produces red.

Why CMYK adds a black

In theory, equal amounts of cyan, magenta and yellow make black. In practice real inks are impure, so the result is a muddy brown, and it also soaks the paper with three layers of ink (slow drying, expensive). Printers therefore add a fourth ink, K for "key" (black), giving CMYK. Black text is also printed far more sharply with one black ink than with three misregistered colors.

A simple, common conversion from RGB takes the amount of black from the darkest ink need and removes it from the colors:

TEXT
K = 1 - max(R, G, B)
C = (1 - R - K) / (1 - K)
M = (1 - G - K) / (1 - K)
Y = (1 - B - K) / (1 - K)        (if K = 1 the color is pure black: C = M = Y = 0)

The reverse is R = (1 - C) * (1 - K), and similarly for G and B. Check with white (1, 1, 1): K = 0, C = M = Y = 0, no ink at all. Check with a mid-grey (0.5, 0.5, 0.5): K = 0.5 and C = M = Y = 0; only black ink is used, as a printer would.

These formulas are the textbook shortcut, and they are exactly what you need for graphics code and learning. Real print workflows use ICC color profiles that describe how a specific printer, ink and paper behave, so a "pure red" in the RGB file never matches the printed one exactly.

Gamut: not every color fits

A device can only produce colors inside its gamut, the range of colors it can reproduce. The standard web color space, sRGB, has a gamut that is a triangle drawn between its three primaries on a chart of visible colors. Wide-gamut displays (Display P3, Adobe RGB) have larger triangles that include more saturated greens and reds. CMYK ink printing covers a different, partly overlapping region: some very bright cyans and oranges that a monitor can show cannot be printed, and a few printed colors are outside sRGB.

When a color falls outside a device's gamut, software must map it to something nearby. This is why a vivid screen color often looks duller in print. For the programmer the lesson is simple: RGB values only mean something in relation to a color space, and web images are almost always assumed to be sRGB.

Try it: a live color mixer

Move the three sliders. The swatch shows the RGB color, and the panel shows the same color in hexadecimal, as CMY and as CMYK. Try the corners of the cube: (255, 0, 0), (0, 255, 255), (128, 128, 128).

RGB to CMY and CMYK mixer

For the default orange (230, 120, 40) you will see no cyan to speak of, a medium amount of magenta, plenty of yellow, and a small share of black (about 10%) โ€” the black ink that stands in for the common darkness of the three channels. Set all three sliders equal and watch C, M and Y collapse to 0% while K takes over.

Seeing add versus subtract

The second demo mixes three overlapping discs. On the left they are lights on a black background, combined with the canvas blend mode lighter, which adds the channel values. On the right they are inks on white paper, combined with multiply, which multiplies the channels (each ink keeps only the light it does not absorb).

Additive versus subtractive mixing

The left picture has a white center and yellow, cyan and magenta overlaps; the right picture has a black center and red, green and blue overlaps. The two pictures are each other's negatives, which is the whole relationship between the models in one image.

Choosing a model in code

  • RGB for anything shown on a screen, stored in images, blended and shaded. Almost every graphics library uses it internally.
  • CMYK only when preparing files for print. Browsers and canvas do not use it; you convert at export time, ideally with a color-managed tool.
  • Other models exist because RGB is awkward for humans: you cannot easily say "make this a bit less saturated" or "rotate the hue" with three light intensities. Those tasks are what HSV and HSL are for, covered in HSV, HSL, Gamma and Perceptual Color.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What do you see when red and green light of full strength overlap on a screen?

    RGB is additive: red + green light gives yellow. Adding blue as well would give white.
  2. 2. Which statement about CMY is correct?

    Cyan, magenta and yellow inks absorb red, green and blue respectively, so each ink amount is one minus the matching light amount.
  3. 3. Why does CMYK add a black (K) ink?

    Combining three real inks gives an impure dark brown and uses a lot of ink. A separate black ink prints text and shadows more cleanly.
  4. 4. A pixel has the RGB value (128, 128, 128). With the simple conversion K = 1 - max(R, G, B), roughly what are its CMYK values?

    A neutral grey has R = G = B, so after K takes 1 - 0.5 the remaining cyan, magenta and yellow are all 0.
  5. 5. What is a gamut?

    Different devices cover different regions of visible colors, and colors outside a gamut must be mapped to nearby ones.

Summary

  • RGB is additive: screens emit red, green and blue light, and 8 bits per channel give 16.7 million colors, which form a cube with black and white at opposite corners.
  • CMY is subtractive and complementary: C = 1 - R, M = 1 - G, Y = 1 - B. CMYK adds black ink, with K = 1 - max(R, G, B) in the simple conversion.
  • Gamut limits what a device can show, so conversions between RGB and CMYK are approximations that proper print workflows handle with ICC profiles.
  • Use RGB in code and CMYK only for print output.

Next, we make color easier to reason about: HSV, HSL, Gamma and Perceptual Color.