How many hexadecimal color codes are there?


There are 16,777,216 hexadecimal colors using #RRGGBB notation.

Colors in Computers

Colors in computers are expressed by combining red, green and blue in different proportions. There are 2 ways to write a color. RGB which has a range of 0-255 for Red, Green and Blue and the Second way is hexadecimal (#RRGGBB).

HexaDecimal Color Codes

Hexadecimal colors use sixteen different values to represent a single shade of color, whether it be red, green, or blue. Each color is broken down into a number or character, ranging from 0-9 and A-F, where 0 is the minimum value and F is the maximum. The color format is separated into #RRGGBB, where RR is red, GG is green, and BB is blue. Each of the 2-symbol elements expresses a color value from 0 to 255.

  1. Element 1: Red value
  2. Element 2: Green value
  3. Element 3: Blue value

The code is written using a formula that turns each value into a unique 2-digit alphanumeric code. For example, the RGB code (92, 153, 114) is 5C9972 in hexadecimal code. This gives you an idea of just how many color combinations are possible with hex color codes.


There are 6 digits in total with 2 digits for each color channel. Each color channel is described using 1 byte of information. Byte can contain 256 different values. If you use RGB, the range of colors is 0-255. Meaning there are 256 possible values for each Red, Green and Blue. So for 3 channels, it is:

256^3 = 16,777,216 = 16M

So you have hex 00 00 00 to FF FF FF or using web terminology;

#000000 to #FFFFFF

However, modern browsers support transparency - #AARRGGBB.

By similar logic you get:

256^4 = 4,294,967,296 = 4G

Here are some examples of hex color codes and their decimal RGB equivalents:

#FFFFFF - (255, 255, 255) White Color #000000 - (0, 0, 0) Black Color #FF0000 - (255, 0, 0) Red Color #000080 - (0, 0, 128) Dark Blue Color

JavaScript Hex Color Codes

What are hex Color codes

Here is a simple node program that return an array of all the possible hex code in JavaScript.

function getHexColorCodes(){ var hexCode = [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E' ,'F']; var arr = []; for (var i = 0; i < hexCode.length; i++) { console.log(`Loop it ${i+1} times`); for (var y = 0; y < hexCode.length; y++) { for (var x = 0; x < hexCode.length; x++) { for (var a = 0; a < hexCode.length; a++) { for (var b = 0; b < hexCode.length; b++) { for (var c = 0; c < hexCode.length; c++) { arr.push(`#${hexCode[i]}${hexCode[y]}${hexCode[x]}${hexCode[a]}${hexCode[b]}${hexCode[c]}\n`); } } } } } } return arr; } var hexColors = getHexColorCodes(); console.log("Total hex colors : " + hexColors.length);
Loop it 1 times Loop it 2 times Loop it 3 times Loop it 4 times Loop it 5 times Loop it 6 times Loop it 7 times Loop it 8 times Loop it 9 times Loop it 10 times Loop it 11 times Loop it 12 times Loop it 13 times Loop it 14 times Loop it 15 times Loop it 16 times Total hex colors : 16777216

It is important to note that hexadecimal color values are supported in all modern browsers. Also, there is a shorthand version of hex colours used in CSS, where you can write something like #567. This is just shorthand for #556677. It saves a few characters when you have a colour with repeating digits in each channel. For example, white is #FFF instead of #FFFFFF.

NEXT.....Add a Color Picker in your web-site