← All TOOLZORQ tools · More guides
1 December 2026
Short answer: Split the HEX code into three pairs — red, green and blue — and turn each pair into a number from 0 to 255. #1DB954 splits into 1D, B9 and 54, giving rgb(29, 185, 84). Each pair is first digit × 16 + second digit, with A to F worth 10 to 15.
A designer hands you #FF6B35 and asks for the same orange in an app that only accepts RGB. HEX and RGB are not two different colours — they are two ways of writing the exact same colour, and converting between them is simple arithmetic once you know the rule. This guide shows the rule with real colours, covers the shorthand and transparency forms, and ends with the code for CSS, JavaScript and Python.
A HEX colour code is a colour written in hexadecimal, the base-16 number system. It starts with a # followed by six characters: two for red, two for green and two for blue. The code #FF6B35 is a warm orange — FF for red, 6B for green, 35 for blue. The # is only a marker; drop it before doing the maths.
Hexadecimal uses sixteen symbols: the digits 0 to 9, then the letters A to F, where A means 10, B means 11, C means 12, D means 13, E means 14 and F means 15. Two hexadecimal digits can represent any number from 0 to 255 — exactly the range one colour channel needs. Case does not matter: #ff6b35 and #FF6B35 are the same colour.
RGB stands for red, green and blue — the three colours of light that screens mix to make every colour you see. An RGB value is three numbers, each from 0 to 255, inside rgb(): rgb(255, 107, 53) is the same warm orange as #FF6B35. 0 means none of that light; 255 means full strength. Black is rgb(0, 0, 0) because all three lights are off, and white is rgb(255, 255, 255) because all three are fully on. One channel is a single byte, holding 256 values, 0 to 255 — which is why HEX and RGB line up so cleanly.
For each pair, multiply the first digit by 16 and add the second; A to F count as 10 to 15. So a pair XY is worth X × 16 + Y.
This works because hexadecimal is base 16: the left digit is the "sixteens" column and the right digit the "ones" column, as in decimal 53 = 5 × 10 + 3. Shortcuts: FF is always 255, and a pair ending in 0, such as 50, is the first digit times 16 — so 50 is 80.
Take #1DB954, the green used by Spotify.
Step 1: drop the # and split the six characters into three pairs: 1D (red), B9 (green), 54 (blue).
Step 2: convert red, 1D: D is 13, so 1 × 16 + 13 = 29.
Step 3: convert green, B9: B is 11, so 11 × 16 + 9 = 185.
Step 4: convert blue, 54: 5 × 16 + 4 = 84.
Step 5: write the three numbers in order: rgb(29, 185, 84). That is the whole method.
More conversions, checked by calculation. The edge cases: #000000 is black, rgb(0, 0, 0), and #FFFFFF is white, rgb(255, 255, 255).
| HEX | Pairs | RGB |
|---|---|---|
| #FF6B35 | FF, 6B, 35 | rgb(255, 107, 53) |
| #4CAF50 | 4C, AF, 50 | rgb(76, 175, 80) |
| #3498DB | 34, 98, DB | rgb(52, 152, 219) |
| #FFD700 | FF, D7, 00 | rgb(255, 215, 0) |
| #800080 | 80, 00, 80 | rgb(128, 0, 128) |
| #F4A460 | F4, A4, 60 | rgb(244, 164, 96) |
| #2E4057 | 2E, 40, 57 | rgb(46, 64, 87) |
| #FF5733 | FF, 57, 33 | rgb(255, 87, 51) |
Some codes have only three digits, such as #3A7. This is shorthand: each digit is doubled, so #3A7 becomes #33AA77. Convert it as before: 33 is 3 × 16 + 3 = 51, AA is 10 × 16 + 10 = 170, and 77 is 7 × 16 + 7 = 119, giving rgb(51, 170, 119).
Shorthand only works when each pair has two identical digits. #F00 doubles to #FF0000, pure red, rgb(255, 0, 0). #ABC doubles to #AABBCC: AA = 170, BB = 187 and CC = 204, giving rgb(170, 187, 204). #1DB954 has no shorthand form — its pairs are not doubled digits.
Tip: double each digit — do not add a zero. #3A7 is #33AA77, not #30A070.
Modern CSS also accepts eight-digit HEX codes, where the last two digits describe the alpha channel — opacity. The format is #RRGGBBAA: the first six digits are the colour, and the last two are the transparency, from 00 (fully transparent) to FF (fully opaque). Convert the alpha pair to a number from 0 to 255 and divide by 255 to get a decimal from 0 to 1.
For example, #1DB95480 is Spotify green at half opacity: the colour is rgb(29, 185, 84), and the alpha pair 80 is 8 × 16 = 128, so the opacity is 128 ÷ 255, about 0.50 — in CSS, rgba(29, 185, 84, 0.5). A code ending in 00 is fully transparent, and one ending in FF is fully opaque, the same as the six-digit version.
Converting the other way round uses division by 16 instead of multiplication. For each RGB number, divide by 16. The whole-number part of the answer — the quotient — becomes the first HEX digit, and the remainder becomes the second. The digits 10 to 15 are written as A to F.
Take rgb(29, 185, 84). Red: 29 ÷ 16 = 1 remainder 13, so 1D. Green: 185 ÷ 16 = 11 remainder 9, so B9. Blue: 84 ÷ 16 = 5 remainder 4, so 54. Join them: #1DB954.
One more, checked by calculation: rgb(52, 152, 219) is 34, 98 and DB — #3498DB — because 52 ÷ 16 = 3 remainder 4, 152 ÷ 16 = 9 remainder 8, and 219 ÷ 16 = 13 remainder 11. Always write two digits per channel: add a leading zero below 16 (5 becomes 05), and remember 0 is 00 and 255 is FF.
In CSS you rarely need to convert at all: the stylesheet accepts both formats, so color: #FF6B35; and color: rgb(255, 107, 53); mean exactly the same thing. You need the conversion when you want to add transparency to a HEX colour, because rgb() accepts a fourth number for opacity and a six-digit HEX code cannot.
To make #1DB954 half transparent in CSS, write background-color: rgba(29, 185, 84, 0.5);. Modern CSS also accepts the eight-digit HEX form directly, background-color: #1DB95480;, and the newer space-separated syntax, rgb(29 185 84 / 50%). All three describe the same semi-transparent green.
JavaScript's parseInt() understands hexadecimal with 16 as the second argument. This function handles six-digit codes and the three-digit shorthand:
function hexToRgb(hex) {
hex = hex.replace('#', '');
if (hex.length === 3) {
hex = hex.split('').map(c => c + c).join('');
}
return {
r: parseInt(hex.slice(0, 2), 16),
g: parseInt(hex.slice(2, 4), 16),
b: parseInt(hex.slice(4, 6), 16)
};
}
hexToRgb('#1DB954'); // { r: 29, g: 185, b: 84 }
hexToRgb('#3A7'); // { r: 51, g: 170, b: 119 }
It strips the #, doubles each character for three-digit codes, then reads each pair with parseInt(pair, 16). Going the other way, convert each channel with toString(16) and pad to two characters — a value below 16 would otherwise give a single digit and break the code.
function rgbToHex(r, g, b) {
return '#' + [r, g, b]
.map(n => n.toString(16).padStart(2, '0'))
.join('').toUpperCase();
}
rgbToHex(29, 185, 84); // '#1DB954'
Python's int() takes a base argument too:
hex_code = '#1DB954'
h = hex_code.lstrip('#')
r, g, b = (int(h[i:i+2], 16) for i in (0, 2, 4))
print(r, g, b) # 29 185 84
For the reverse direction, format each channel as two uppercase hex digits with :02X, which pads with a leading zero:
r, g, b = 29, 185, 84
hex_code = f'#{r:02X}{g:02X}{b:02X}'
print(hex_code) # #1DB954
On the command line: python3 -c "print(tuple(int('#1DB954'.lstrip('#')[i:i+2], 16) for i in (0, 2, 4)))" prints (29, 185, 84). For a whole list of colours, wrap either snippet in a loop.
Doing the maths by hand is useful once. Doing it for every colour in a project is slow. TOOLZORQ's Color Picker does the conversion for you: type a HEX value and it shows the RGB and HSL values instantly, with a shades and tints palette built from your colour. Click any swatch to copy its HEX code. It runs entirely in your browser, needs no sign-up, and nothing you type leaves your device.
Use the hand method to understand a colour or check a single value, and the Color Picker when building a real palette. To build the lighter and darker versions of your base colour, see How to Make Shades and Tints of a Colour — the palette gives you those steps ready made.
Most errors come from a small slip. First, forgetting the letters: A is 10, not 1, so B9 is 11 × 16 + 9 = 185. Second, reading the pairs in the wrong order — the first pair is always red, the second green and the third blue, so swapping pairs gives a different colour. Third, treating a three-digit code as if it were six digits: #3A7 is #33AA77, not #3A7000. Fourth, dropping the leading zero when converting back — a channel value of 5 becomes the pair 05, and writing just 5 leaves a five-digit code no browser accepts. Fifth, mixing up the direction: HEX to RGB multiplies by 16, RGB to HEX divides by 16. Case does not matter, but a missing # or an extra character will make a tool reject the code.
Watch out: an RGB value above 255 is impossible. If your working gives a number over 255, you have slipped — a HEX pair can never be more than FF, which is 255.
The colours people look up most often, worked out with the same formula:
| Colour | HEX | RGB |
|---|---|---|
| Black | #000000 | rgb(0, 0, 0) |
| White | #FFFFFF | rgb(255, 255, 255) |
| Red | #FF0000 | rgb(255, 0, 0) |
| Lime | #00FF00 | rgb(0, 255, 0) |
| Blue | #0000FF | rgb(0, 0, 255) |
| Yellow | #FFFF00 | rgb(255, 255, 0) |
| Cyan | #00FFFF | rgb(0, 255, 255) |
| Magenta | #FF00FF | rgb(255, 0, 255) |
| Silver | #C0C0C0 | rgb(192, 192, 192) |
| Gray | #808080 | rgb(128, 128, 128) |
| Purple | #800080 | rgb(128, 0, 128) |
Split the code into three pairs — red, green, blue — and convert each with first digit × 16 + second digit, A to F counting as 10 to 15. #1DB954 becomes rgb(29, 185, 84). For repeated conversions, use TOOLZORQ's Color Picker.
Yes. #FF0000 splits into FF, 00 and 00, which are 255, 0 and 0 — exactly rgb(255, 0, 0). HEX and RGB are two notations for the same three numbers.
FF is the largest value a two-digit HEX pair can hold: 15 × 16 + 15 = 255. It means that channel is at full strength — FF in the red position is maximum red, and #FFFFFF is white because all three channels are at 255.
Double each digit to make six: #F00 becomes #FF0000, which is rgb(255, 0, 0). Shorthand only works when each pair is made of two identical digits.
Add two HEX digits for the alpha channel — #RRGGBBAA — where 00 is fully transparent and FF is fully opaque. #1DB95480 is Spotify green at about 50 percent opacity; in CSS, rgba(29, 185, 84, 0.5).
Check four things: the code has exactly six digits (or three, or eight) after the #; every character is 0–9 or A–F; the # is present; and the digits are in red-green-blue order.
HEX and RGB are the same colour written two ways, and the bridge between them is one small piece of arithmetic: split the code into pairs, multiply the first digit of each pair by 16, and add the second.