Colours are #RRGGBB. Memory addresses are 0x7fff. Permissions are 0o755. Once you see why hexadecimal maps so cleanly onto bytes, all of it stops looking like arbitrary code.

Hex shows up the moment you go even slightly below the surface of software. A colour is #3498db. A memory address is 0x7ffe. A file permission is 0o755. It looks like a secret language, and beginners often just copy the magic strings without knowing why they're in these odd bases. But there's a clean, practical reason computing runs on base 16 and base 2, and once it clicks, the "magic" turns into something you can read at a glance.

What a base actually is

A number base is just how many symbols you count with before rolling over to a new place. We use base 10 out of habit (ten fingers), with digits 0–9. Binary is base 2 — only 0 and 1. Hexadecimal is base 16. Wikipedia states it directly:

"Hexadecimal is a positional numeral system for representing a numeric value as base 16. For the most common convention, a digit is represented as '0' to '9' like for decimal and as a letter of the alphabet from 'A' to 'F' for the digits with decimal value 10 to 15."

— Wikipedia, "Hexadecimal" (CC BY-SA 4.0)

So hex needs sixteen symbols: the digits 0–9 plus A–F for ten through fifteen. That's the whole apparent weirdness — the letters are just digits.

Why hex and bytes are made for each other

Here's the reason computing loves hex. A byte is 8 bits, and 8 bits split perfectly into two groups of 4. A group of 4 bits (a "nibble") has exactly 16 possible values — 0000 to 1111 — which is precisely one hex digit, 0 to F. So one byte is always exactly two hex digits, no more, no less. That clean, fixed mapping is why hex is everywhere bytes are: it's a compact, unambiguous way to write binary. Base 10 has no such tidy relationship with bytes (255 is three digits, 16 is two — messy), which is exactly why raw byte values are shown in hex, not decimal.

Why colours are hex

A web colour like #3498db is three bytes: red, green, blue, each one byte (0–255). Written in hex, each byte is two digits, so the colour is six hex digits — 34 red, 98 green, db blue. The format isn't arbitrary; it's three bytes shown two-hex-digits-each. Once you know that, you can read a hex colour: #ff0000 is maximum red and no green or blue, i.e. pure red. The same logic explains 0x memory addresses and hex-encoded hashes — they're all just bytes made readable.

Reading between bases without memorising

You don't need to memorise conversion tables. The trick for hex-to-binary is that each hex digit independently becomes four bits, so you can convert one digit at a time: D is 13 is 1101, B is 11 is 1011, so DB is 11011011. Decimal is the awkward one to convert by hand precisely because it doesn't align with bits — which is the whole reason low-level work avoids it. When you need decimal, that's what a converter is for; when you're working with bytes, staying in hex keeps everything aligned.

Octal — the base you forgot about

Base 8 gets less attention than hex but it's the reason Unix file permissions look the way they do. In octal, each digit maps to exactly three bits, so the permission value 755 decomposes into three three-bit groups: 111 (owner: read-write-execute), 101 (group: read-execute), 101 (others: read-execute). The base was chosen because permissions are three-bit fields, and octal maps to three bits the same way hex maps to four. When you run chmod 644, you're setting three separate bit-masks in a notation designed to make each one a single digit. It's the same idea as hex-for-bytes, just at a smaller scale.

When decimal is actually right

Hex and binary are tools for working with bytes — but not everything in software is a byte-level concern. Array indices, loop counters, pixel coordinates, HTTP status codes, database IDs — all of these are quantities, and quantities belong in decimal because that's the base humans do arithmetic in. Writing a loop counter in hex doesn't help anyone; it's the same number wearing a harder-to-read costume. The rule of thumb: use hex when the value represents bytes, bits, or bit-masks. Use decimal when the value represents a count, a position, or a measurement. The choice is about what the number means, not a style preference.

Hex in the wild: hashes, MAC addresses, and UUIDs

Once you know that hex is just a compact way to write bytes, a lot of seemingly cryptic formats become readable. A SHA-256 hash is 32 bytes, so it's 64 hex digits — each pair is one byte of the digest. A MAC address like 00:1A:2B:3C:4D:5E is six bytes, each shown as two hex digits separated by colons. A UUID like 550e8400-e29b-41d4-a716-446655440000 is 16 bytes with hyphens inserted for readability at fixed positions. None of these formats were designed to be cryptic; they're all just "bytes, written in hex, with separators." Knowing that one fact decodes all of them.

Convert and inspect

Build the intuition by watching the bases line up. A number base converter lets you type a value once and see it in decimal, hex, and binary together — flip a byte between 219, DB, and 11011011 and the two-hex-digits-per-byte rule becomes obvious. An ASCII table shows how characters map to numeric codes in decimal and hex side by side (capital A is 65, or 0x41), which is where a lot of "why is this byte that number" questions get answered. And for characters beyond ASCII, a Unicode inspector shows the hex code points that identify every character. Hex isn't a developer affectation — it's the most honest way to write what the machine is actually holding, one nibble at a time.

← All articles