Decimal to Hex Converter
Convert base-10 numbers to base-16 hexadecimal (decimal to hex)
Decimal to hex: divide by 16 repeatedly, write remainders 10–15 as A–F, and read them from last to first. For example, 255 = FF, 1,000 = 3E8 and 48,879 = BEEF.
How to convert decimal to hexadecimal
Hexadecimal is base 16. It needs sixteen digit symbols, so after 0 to 9 it borrows the letters A to F for the values 10 to 15. Each place is worth sixteen times the place to its right: 1, 16, 256, 4,096, 65,536 and so on. Converting from decimal means finding how many of each place value the number contains, and repeated division by 16 does that one place at a time, starting with the ones. Octal, binary and the other bases share the number system converter.
Two traps catch most people. First, a remainder of 10 or more must become a single letter, so a remainder of 14 is E, never "14". Second, the remainders emerge lowest place first, so you must read them from the last to the first. Hex is also a compact way to write binary, since one hex digit is exactly four bits; the decimal to binary converter shows the same number bit by bit.
Step by step
- Divide the decimal number by 16 and note the remainder, a value from 0 to 15.
- Write remainders 10 to 15 as the letters A to F.
- Divide the quotient by 16 again and repeat until the quotient is 0.
- Read the remainders from last to first; add 0x in code or # for a color.
See the place values
Worked examples
A single byte, a four-digit year and a larger number that happens to spell a word in hex.
171 ÷ 16 = 10 r B; 10 ÷ 16 = 0 r A. Reading the remainders from bottom to top gives AB₁₆.
= AB₁₆
2026 ÷ 16 = 126 r A; 126 ÷ 16 = 7 r E; 7 ÷ 16 = 0 r 7. Reading the remainders from bottom to top gives 7EA₁₆.
= 7EA₁₆
48879 ÷ 16 = 3054 r F; 3054 ÷ 16 = 190 r E; 190 ÷ 16 = 11 r E; 11 ÷ 16 = 0 r B. Reading the remainders from bottom to top gives BEEF₁₆.
= BEEF₁₆
How do I convert decimal to hex in Excel or Google Sheets?
Use =DEC2HEX(A2): with 255 in A2 it returns FF, and =DEC2HEX(A2,4) pads the result to 00FF.
DEC2HEX accepts whole numbers from −549,755,813,888 to 549,755,813,887, the range of a 40-bit two's complement value, and returns negative numbers as ten hex digits, so =DEC2HEX(-1) gives FFFFFFFFFF. For larger positive numbers, =BASE(A2,16) works for any whole number below 253. Both return uppercase letters; wrap them in LOWER() if a style guide wants lowercase. For values pasted into code, add the prefix yourself: ="0x"&DEC2HEX(A2,8) turns 255 into 0x000000FF, the usual 32-bit width.
A hex color from separate channels is one formula: with red, green and blue in B2, C2 and D2, ="#"& turns 255, 99, 71 into #FF6347. In code, Python's format(255, "X") returns FF and JavaScript's (255).toString(16) returns the lowercase ff.
How do you convert hex back to decimal?
Multiply each hex digit by 16 raised to its position, counting from 0 on the right, and add: 3E8 = 3 × 256 + 14 × 16 + 8 = 1,000.
Treat A to F as 10 to 15 before you multiply. Three more worked examples:
- FF = 15 × 16 + 15 = 255
- 7D0 = 7 × 256 + 13 × 16 + 0 = 2,000
- BEEF = 11 × 4,096 + 14 × 256 + 14 × 16 + 15 = 48,879
You can also type the hex value into the lower box of the converter above, which works in both directions. In a spreadsheet, =HEX2DEC("3E8") returns 1,000; it reads ten-digit values that start with 8 to F as negative two's complement numbers, so use =DECIMAL(A2,16) for large unsigned values. In Python, int("3E8", 16) gives 1000.
Why do programmers use hexadecimal?
Programmers use hexadecimal because each hex digit stands for exactly 4 bits, so a byte is always two digits and a 32-bit value always eight.
That fixed mapping makes hex a readable shorthand for binary. The 32-bit pattern 11111111111111110000000000000000 is hard to scan, but FFFF0000 shows at a glance that the top 16 bits are set. Decimal hides this structure: the same value is 4,294,901,760, and nothing in those digits shows where one byte ends. Round binary quantities look round in hex too: 230 bytes, the gibibyte explained on the MB to GB converter, is 0x40000000.
Octal, which groups bits in threes, suited machines whose word sizes divide by 3, such as the 12-bit PDP-8 and the 36-bit PDP-10. Hex fits 8-bit bytes exactly and replaced octal on most later systems; octal survives mainly in Unix file permissions such as 755.
Decimal to hex conversion chart
Single digits, the letter digits A to F, and the byte and word boundaries programmers use most, such as 255 (FF), 4,096 (1000) and 65,535 (FFFF).
| Decimal (base 10) | Hexadecimal (base 16) |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 5 | 5 |
| 9 | 9 |
| 10 | A |
| 11 | B |
| 12 | C |
| 13 | D |
| 14 | E |
| 15 | F |
| 16 | 10 |
| 17 | 11 |
| 20 | 14 |
| 26 | 1A |
| 31 | 1F |
| 32 | 20 |
| 42 | 2A |
| 50 | 32 |
| 64 | 40 |
| 100 | 64 |
| 127 | 7F |
| 128 | 80 |
| 160 | A0 |
| 192 | C0 |
| 200 | C8 |
| 255 | FF |
| 256 | 100 |
| 500 | 1F4 |
| 512 | 200 |
| 1000 | 3E8 |
| 1024 | 400 |
| 4095 | FFF |
| 4096 | 1000 |
| 10000 | 2710 |
| 65535 | FFFF |
Decimal vs hexadecimal: what is the difference?
Decimal and hexadecimal write the same integers with different bases. Hex trades familiarity for a perfect fit with binary, which is why computers display it even though people rarely count in it.
| Attribute | Decimal | Hexadecimal |
|---|---|---|
| Symbol | — | — |
| System | Base 10 | Base 16 |
| Defined as | digits 0–9 | digits 0–9, A–F |
| Digits used | 0–9 | 0–9 and A–F |
| Place values (right to left) | 1, 10, 100, 1,000 … | 1, 16, 256, 4,096 … |
| Bits per digit | About 3.32 | Exactly 4 |
| Largest 2-digit value | 99 | FF = 255 |
| Prefix or marker | None | 0x in code, # in CSS colors, U+ in Unicode |
| Used for | Everyday numbers, prices, measurements | Memory addresses, color codes, MAC addresses, Unicode code points |
5 key differences
- Two hex digits cover exactly one byte, from 00 to FF, which is 0 to 255 in decimal.
- Large values need fewer hex digits: 4,294,967,295 takes 10 decimal digits but only 8 in hex (FFFFFFFF).
- Hex letters are case-insensitive, so 0xff, 0xFF and 0XFF all mean 255.
- Decimal 10 is A in hex, while hex 10 means decimal 16, so always mark which base a number is in.
- CSS accepts both notations for the same color: rgb(70 130 180) and #4682B4 are identical.
What do A to F mean in hexadecimal?
In hexadecimal, A to F are single digits worth 10 to 15, and they are the only new symbols to learn. Each is shown with its decimal value and its 4-bit binary pattern, which is why two hex digits describe one byte exactly. Case does not matter: 0xff and 0xFF are the same number.
| Decimal | Hex digit | Binary (4 bits) |
|---|---|---|
| 10 | A | 1010 |
| 11 | B | 1011 |
| 12 | C | 1100 |
| 13 | D | 1101 |
| 14 | E | 1110 |
| 15 | F | 1111 |
Hexadecimal place values
Each hex place is a power of 16. A number that needs more than eight hex digits is larger than 4,294,967,295, the maximum of a 32-bit unsigned integer.
| Position | Power | Decimal value | Hex |
|---|---|---|---|
| 0 | 16⁰ | 1 | 1 |
| 1 | 16¹ | 16 | 10 |
| 2 | 16² | 256 | 100 |
| 3 | 16³ | 4,096 | 1000 |
| 4 | 16⁴ | 65,536 | 10000 |
| 5 | 16⁵ | 1,048,576 | 100000 |
| 6 | 16⁶ | 16,777,216 | 1000000 |
| 7 | 16⁷ | 268,435,456 | 10000000 |
| 8 | 16⁸ | 4,294,967,296 | 100000000 |
Is there a shortcut for decimal to hex?
Yes: go through binary and group the bits in fours, or divide by 256 so that each step produces two hex digits at once.
Via binary. Convert to binary first, split the bits into groups of four from the right, and replace each group with one hex digit. 2,026 is 11111101010 in binary; grouped, that is 0111 1110 1010, which reads 7 E A, so 2,026 = 7EA.
By bytes. For larger numbers, divide by 256 instead of 16, and convert each remainder to a two-digit hex pair. 48,879 ÷ 256 = 190 remainder 239. Since 190 = BE and 239 = EF, the answer is BEEF. This is how memory addresses and file bytes are usually read.
To reverse any result, multiply each hex digit by its place value and add, just as the binary to decimal converter does with powers of two.
RGB to hex color codes
A CSS hex color is three bytes: red, green and blue, each converted from 0 to 255 in decimal into two hex digits from 00 to FF. The names are standard CSS named colors. Pair the codes with the px to rem converter when you build a style sheet.
| CSS color | RGB (decimal) | Each channel in hex | Hex code |
|---|---|---|---|
| Steel blue | rgb(70, 130, 180) | 46 82 B4 | #4682B4 |
| Tomato | rgb(255, 99, 71) | FF 63 47 | #FF6347 |
| Sea green | rgb(46, 139, 87) | 2E 8B 57 | #2E8B57 |
| Goldenrod | rgb(218, 165, 32) | DA A5 20 | #DAA520 |
| Indigo | rgb(75, 0, 130) | 4B 00 82 | #4B0082 |
| Coral | rgb(255, 127, 80) | FF 7F 50 | #FF7F50 |
| Rebecca purple | rgb(102, 51, 153) | 66 33 99 | #663399 |
| Alice blue | rgb(240, 248, 255) | F0 F8 FF | #F0F8FF |
| Slate gray | rgb(112, 128, 144) | 70 80 90 | #708090 |
| Crimson | rgb(220, 20, 60) | DC 14 3C | #DC143C |
Where is decimal to hex used?
Decimal to hex comes up wherever software shows raw bytes to people: color codes, character codes, memory addresses, error codes and hardware IDs.
- Web colors: design tools often give RGB values, while CSS and brand guides use hex codes like #4682B4.
- Unicode and HTML: the character é is code point 233, written U+00E9. In HTML it can be written as the decimal reference é or the hex reference é.
- Memory and debugging: addresses, pointers and byte dumps are shown in hex, so an offset of 4,096 bytes appears as 0x1000.
- Error codes: Windows reports errors such as 0x80070005 in hex, and converting to decimal helps when documentation lists the other form.
- Hardware IDs: MAC addresses, USB vendor IDs and IPv6 addresses are written as hex groups.
Watch the notation
Hex numbers carry different markers depending on context: 0x in C, Java, JavaScript and Python, # for CSS colors, U+ for Unicode, and a trailing h in some assembly languages. The three-digit CSS shorthand doubles each digit, so #ABC means #AABBCC. Other bases are on the number system converter.
Sources and further reading
The standards and references behind the numbers on this page. Links open in a new tab.
Further reading
- DecimalWikipedia
- HexadecimalWikipedia
Decimal to hex FAQs
Short, exact answers to what people ask most.
How do you convert decimal to hex?
Divide the number by 16 and write down the remainder, using A to F for 10 to 15, then repeat with the quotient until it is 0. Read the remainders from last to first; 200 becomes C8.
What is 255 in hex?
255 in decimal is FF in hexadecimal: 15 × 16 + 15 = 255. It is the largest value that fits in one byte.
What is 100 in hex?
100 in decimal is 64 in hexadecimal, because 6 × 16 + 4 = 100. Note that hex 64 and decimal 64 are different numbers.
What is 1000 in hex?
1,000 in decimal is 3E8 in hexadecimal: 3 × 256 + 14 × 16 + 8 = 1,000.
How do I convert RGB to a hex color code?
Convert each of the red, green and blue values from decimal to a two-digit hex number and join them after a # sign. For example, rgb(70, 130, 180) becomes #4682B4.
What is the largest 4-digit hex number?
FFFF is the largest 4-digit hex number, equal to 65,535 in decimal. It is the maximum value of an unsigned 16-bit integer.
What is 16 in hex?
16 in decimal is 10 in hexadecimal: one sixteen and zero ones.
What is 10 in hex?
10 in decimal is A in hexadecimal, the first of the letter digits.
What is 128 in hex?
128 in decimal is 80 in hex, because 8 × 16 = 128. It is the value of the top bit in a byte.
What is 500 in hex?
500 in decimal is 1F4 in hexadecimal: 1 × 256 + 15 × 16 + 4 = 500.
What is 4096 in hex?
4,096 in decimal is 1000 in hexadecimal, since 4,096 is 16 cubed.
What is 65536 in hex?
65,536 in decimal is 10000 in hex. It is 16 to the 4th power, one more than FFFF, the largest 16-bit value.
Related conversions
Hex color syntax and named colors from the W3C CSS Color Module Level 4; code point notation from The Unicode Standard; base conversion from Knuth, The Art of Computer Programming, Vol. 2; DEC2HEX, HEX2DEC, DECIMAL and BASE from the Microsoft Excel and Google Sheets documentation. Last updated . How we verify our numbers.