Measurement
Science & Engineering
Digital & Data
Everyday
Popular converters All converters Blog About

Decimal to Hex Converter

Convert base-10 numbers to base-16 hexadecimal (decimal to hex)

Quick answer

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.

Free · no sign-upUpdated

Decimal to Hexadecimal converter

Live
Decimal
Hexadecimal
Try
Also equals

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.

Formula
divide by 16, keep the remainders
read the remainders from the last to the first

Step by step

  1. Divide the decimal number by 16 and note the remainder, a value from 0 to 15.
  2. Write remainders 10 to 15 as the letters A to F.
  3. Divide the quotient by 16 again and repeat until the quotient is 0.
  4. Read the remainders from last to first; add 0x in code or # for a color.

See the place values

7EA16 = 7 × 256 + 14 × 16 + 10 × 1 = 2,026

Worked examples

A single byte, a four-digit year and a larger number that happens to spell a word in hex.

Example 1: 171₁₀ to hexadecimal

171 ÷ 16 = 10 r B; 10 ÷ 16 = 0 r A. Reading the remainders from bottom to top gives AB₁₆.

= AB₁₆

Example 2: 2026₁₀ to hexadecimal

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₁₆

Example 3: 48879₁₀ to hexadecimal

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₁₆

255₁₀ = FF₁₆255 in both bases
1024₁₀ = 400₁₆1,024 (2¹⁰)

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, ="#"&DEC2HEX(B2,2)&DEC2HEX(C2,2)&DEC2HEX(D2,2) 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 to hex conversion chart
Decimal (base 10)Hexadecimal (base 16)
11
22
55
99
10A
11B
12C
13D
14E
15F
1610
1711
2014
261A
311F
3220
422A
5032
6440
10064
1277F
12880
160A0
192C0
200C8
255FF
256100
5001F4
512200
10003E8
1024400
4095FFF
40961000
100002710
65535FFFF

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.

Decimal vs hexadecimal: what is the difference?
AttributeDecimalHexadecimal
Symbol——
SystemBase 10Base 16
Defined asdigits 0–9digits 0–9, A–F
Digits used0–90–9 and A–F
Place values (right to left)1, 10, 100, 1,000 …1, 16, 256, 4,096 …
Bits per digitAbout 3.32Exactly 4
Largest 2-digit value99FF = 255
Prefix or markerNone0x in code, # in CSS colors, U+ in Unicode
Used forEveryday numbers, prices, measurementsMemory addresses, color codes, MAC addresses, Unicode code points

5 key differences

  1. Two hex digits cover exactly one byte, from 00 to FF, which is 0 to 255 in decimal.
  2. Large values need fewer hex digits: 4,294,967,295 takes 10 decimal digits but only 8 in hex (FFFFFFFF).
  3. Hex letters are case-insensitive, so 0xff, 0xFF and 0XFF all mean 255.
  4. Decimal 10 is A in hex, while hex 10 means decimal 16, so always mark which base a number is in.
  5. 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.

What do A to F mean in hexadecimal?
DecimalHex digitBinary (4 bits)
10A1010
11B1011
12C1100
13D1101
14E1110
15F1111

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.

Hexadecimal place values
PositionPowerDecimal valueHex
016⁰11
116¹1610
216²256100
316³4,0961000
416⁴65,53610000
516⁵1,048,576100000
616⁶16,777,2161000000
716⁷268,435,45610000000
816⁸4,294,967,296100000000

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.

RGB to hex color codes
CSS colorRGB (decimal)Each channel in hexHex code
Steel bluergb(70, 130, 180)46 82 B4#4682B4
Tomatorgb(255, 99, 71)FF 63 47#FF6347
Sea greenrgb(46, 139, 87)2E 8B 57#2E8B57
Goldenrodrgb(218, 165, 32)DA A5 20#DAA520
Indigorgb(75, 0, 130)4B 00 82#4B0082
Coralrgb(255, 127, 80)FF 7F 50#FF7F50
Rebecca purplergb(102, 51, 153)66 33 99#663399
Alice bluergb(240, 248, 255)F0 F8 FF#F0F8FF
Slate grayrgb(112, 128, 144)70 80 90#708090
Crimsonrgb(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

Questions

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.

Keep converting

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.