·7 min read

What is Hexadecimal? A Developer's Guide to Hex

Hexadecimal shows up everywhere in programming — from color codes to memory addresses to MAC addresses. Here's everything you need to know about the base-16 number system.

What is Hexadecimal?

Hexadecimal (often shortened to hex) is a base-16 number system. While the decimal system we use daily has 10 digits (0–9), hexadecimal uses 16 symbols: the digits 0–9 plus the letters A–F.

The word comes from Greek hexa (six) and Latin decem(ten) — literally "six-ten," or sixteen.

In programming, hex values are typically prefixed with 0x to distinguish them from decimal numbers. For example, 0xFF is hexadecimal for 255 in decimal.

Why Do We Use Hexadecimal?

Computers operate in binary (base-2), but binary numbers get very long very quickly. The number 255, for instance, is 11111111 in binary — eight digits. In hex, it's simply FF.

Hex works so well with binary because 16 is a power of 2 (16 = 2⁴). This means:

  • Each hex digit maps exactly to 4 binary digits (a nibble)
  • Two hex digits represent exactly 1 byte (8 bits)
  • Conversion between hex and binary is trivial — just group by 4
  • It's far more compact and readable than raw binary

Hex gives us a human-friendly way to read and write binary data without losing the direct relationship to the underlying bits.

The 16 Hex Digits

Here's the complete hex digit table with decimal and binary equivalents:

HexDecimalBinary
000000
110001
220010
330011
440100
550101
660110
770111
881000
991001
A101010
B111011
C121100
D131101
E141110
F151111

Note that A–F are case-insensitive0xff, 0xFF, and 0XFF all represent the same value.

How to Read Hex Numbers

Hex works just like decimal, except each position represents a power of 16 instead of 10:

Decimal place values:  ... 1000  100  10   1
                           10³  10²  10¹  10⁰

Hex place values:      ... 4096  256  16   1
                           16³   16²  16¹  16⁰

Example: 0x2F4
  2 × 256  =  512
  F × 16   =  240    (F = 15, so 15 × 16)
  4 × 1    =    4
             -----
  Total    =  756 (decimal)

Converting Hex to Decimal

To convert hex to decimal, multiply each digit by its positional power of 16 and add the results:

Example: 0x1A3

  1 × 16² = 1 × 256 = 256
  A × 16¹ = 10 × 16 = 160
  3 × 16⁰ = 3 × 1   =   3
                       -----
  Result:              419

So 0x1A3 = 419 in decimal.

Some common values worth memorizing:

  • 0xFF = 255 (maximum value of one byte)
  • 0x100 = 256
  • 0xFFFF = 65,535 (maximum 16-bit unsigned value)
  • 0x7FFFFFFF = 2,147,483,647 (maximum 32-bit signed integer)

Converting Decimal to Hex

To convert decimal to hex, repeatedly divide by 16 and record the remainders:

Example: Convert 750 to hex

  750 ÷ 16 = 46  remainder 14 (E)
   46 ÷ 16 =  2  remainder 14 (E)
    2 ÷ 16 =  0  remainder  2 (2)

Read remainders bottom-to-top: 2EE

So 750 = 0x2EE

Hex and Binary

The real beauty of hex is how cleanly it maps to binary. Each hex digit is exactly 4 bits, so conversion is just grouping:

Hex to Binary:
  0xA7 → A = 1010, 7 = 0111 → 10100111

Binary to Hex:
  11011110 → 1101 = D, 1110 = E → 0xDE

Byte example:
  0xFF → 11111111 (all bits on, max byte value)
  0x00 → 00000000 (all bits off, zero)

This is why hex is the preferred notation for viewing raw bytes — in hex dumps, memory viewers, and debuggers. Two hex characters always represent exactly one byte, making it easy to scan through binary data.

Hex in the Real World

Hexadecimal appears throughout computing and development:

CSS/HTML Colors

Colors are represented as 3 bytes — Red, Green, Blue — written in hex:

ColorHex CodeRGB ValuesPreview
Red#FF0000255, 0, 0
Green#00FF000, 255, 0
Blue#0000FF0, 0, 255
White#FFFFFF255, 255, 255
Black#0000000, 0, 0

Other Common Uses

  • Memory addresses — Debuggers show addresses like 0x7FFF5FBFF8A0
  • MAC addresses — Network hardware IDs like 00:1A:2B:3C:4D:5E
  • Unicode code points — Characters identified as U+1F600 (😀)
  • Error codes — Windows HRESULT codes like 0x80070005
  • Cryptographic hashes — SHA-256, MD5 output is shown in hex
  • IPv6 addresses — Written in hex: 2001:0db8:85a3::8a2e:0370:7334

Hex in Code

Every major programming language supports hex literals and conversion:

JavaScript

// Hex literals
const value = 0xFF; // 255

// Decimal to hex string
const hex = (255).toString(16); // "ff"

// Hex string to decimal
const dec = parseInt("ff", 16); // 255

// Pad to 2 digits (useful for colors)
const padded = (10).toString(16).padStart(2, "0"); // "0a"

Python

# Hex literals
value = 0xFF  # 255

# Decimal to hex string
hex_str = hex(255)     # '0xff'
formatted = f"{255:02x}"  # 'ff'

# Hex string to decimal
dec = int("ff", 16)  # 255

CSS

/* Full 6-digit hex */
color: #3B82F6;

/* Short 3-digit hex (each digit doubled) */
color: #FFF;  /* same as #FFFFFF */

/* 8-digit hex with alpha transparency */
color: #3B82F680;  /* 50% opacity */

Common Hex Mistakes

A few pitfalls to watch out for:

❌ Confusing hex and decimal

10 in hex is 16 in decimal, not 10. Always use the 0x prefix or # to make it clear.

❌ Forgetting to pad with zeros

A byte should always be 2 hex digits. Writing A instead of 0A can cause parsing errors in some contexts.

❌ Using letters beyond F

Hex only uses A–F. Letters like G, H, or Z are not valid hex digits and will cause errors.

❌ Missing the # in CSS colors

CSS requires the # prefix for hex colors. FF0000 without # won't work.

Convert Hex Values Instantly

Use our free Hex Converter tool to convert between hexadecimal, decimal, binary, and octal — right in your browser with no data uploaded to any server.

Try Hex Converter →

References

  1. Mozilla Developer Network. Hexadecimal — MDN Web Docs Glossary. https://developer.mozilla.org/en-US/docs/Glossary/Hexadecimal
  2. Mozilla Developer Network. <color> — CSS: Cascading Style Sheets. https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
  3. Mozilla Developer Network. parseInt() — JavaScript. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
  4. The Unicode Consortium. Unicode Code Charts. https://www.unicode.org/charts/
  5. IEEE. IEEE 802 — MAC Address Format. https://standards.ieee.org/products-programs/regauth/