There are 256 terminal color escapes available:

  • 8 "system" colors (0 - 7)
  • 8 "bright" system colors (8 - 15)
  • 216, or 6*6*6 "RGB" colors (16 - 231)
  • 24 "grayscale" colors (232 - 255)

The "RGB" colors are what I'm wondering about.

The first six colors, from 16 to 21, map to the following hex RGB values:

  • 16: 000000
  • 17: 000054
  • 18: 000087
  • 19: 0000af
  • 20: 0000d7
  • 21: 0000ff

Now the blue values only, in decimal:

  • 16: 0
  • 17: 84
  • 18: 135
  • 19: 175
  • 20: 215
  • 21: 255

In other words, the RGB value goes up by 84, then 51 (84 + 51 = 135), then 40 the rest of the way.

This cycle of 6 values from 0 to 255 is repeated 36 times, first with blue, then green, then red, eventually forming our "cube" of 216 terminal colors:

All 256 terminal colors

My question is: Why?

Does anyone know if there is a historical/technical reason for this, or was it just an arbitrary decision made by whoever had to decide what the color codes meant? Did this mapping come to exist before RGB was such a universal convention? Why not go up by 42, 42, 42, 43, 43, 43?

  • For me, color number 17 is #00005F (tested in xterm, gnome-terminal, konsole, terminology, st). That is, it goes up by 95, and then 5 times by 40. Still doesn't make too much sense, though. – egmont Apr 25 '15 at 21:38
  • "Why not go up by 42, 42, 42, 43, 43, 43?" You did the math incorrectly. 6x6x6 cube means 5 steps from one end to the other, not 6. That is, you should increment by 51 in each step. I'm really not sure though that that'd look evenly distributed to the human eye. – egmont Apr 25 '15 at 21:39
  • Just for reference, let's mention that several terminal emulators (e.g. gnome-terminal, konsole, st) support arbitrary #rrggbb colors via escape sequences. Alas, support from applications is quite poor. – egmont Apr 25 '15 at 21:41
  • To me, the big question is not why the 6x6x6 color cube looks like this. To me, the big question is why palette-free direct RGB hasn't taken over yet, and why developer are not pushing hard for this. – egmont Apr 25 '15 at 21:45

In the sense suggested, it was "arbitrary": a developer chose to split up the set of 256 colors by reserving the first 16 colors to match existing usage, and then noticed that he could get a cube after discounting a conveniently-sized grayscale ramp. Neither of the developers (256 or 88) referred to human-factors publications. They simply chose the steps of color for convenience in computation and what "looked nice".

The technical details as such are in the xterm FAQ Can I set a color by its number?

In a course that I took in college, it was said to me that the human eye can detect about 256 shades of any one color [or so close that a byte can effectively match that], so 256 of each of the three primary colors allows for all of the colors that the human eye can see. The rest I am unsure of.

  • Found this on wikipedia: "A set of colors was needed that could be shown without dithering on 256-color displays; the number 216 was chosen partly because computer operating systems customarily reserved sixteen to twenty colors for their own use; it was also selected because it allows exactly six equally-spaced shades of red, green, and blue (6 × 6 × 6 = 216), each from 00 to FF (including both limits)." – Jeff Clayton Jul 16 '14 at 1:33
  • The color mapping has me intrigued. – Jeff Clayton Jul 16 '14 at 1:34
  • They're not equally spaced, though--the first two go up by 84 and 51, then the rest by 40. It's entirely possible that the decision was totally arbitrary, but I'm just terribly fascinated as to the potential reasoning if it wasn't. – Max Cantor Jul 16 '14 at 14:43
  • The base 16 system colors are most likely throwbacks that never got changed when 256 color VGA entered int the picture (that really wasn't meant as a play on words :) – Jeff Clayton Jul 16 '14 at 16:28

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.