Binary, octal, hex, and decimal: what each base is actually for

How-to guides 9 min read

Binary, octal, hex, and decimal: what each base is actually for

August 5, 2026 · 9 min read

A number doesn't have an inherent base - 255, 0xff, 0b11111111, and 0o377 are four different ways of writing down the exact same value. Which one you reach for is purely about what's easiest for a human to read in context, because the underlying bits in memory are identical regardless of which base you used to write them.

The same number, four ways

Decimal (base 10) is what humans default to because we have ten fingers, not because it's special to computers. Binary (base 2) is what hardware actually stores - every value is ultimately a sequence of on/off bits. Hex (base 16) and octal (base 8) exist purely as human-readable shorthand for binary, chosen because both are powers of two: one hex digit maps to exactly 4 bits, one octal digit to exactly 3 bits, so converting to and from binary is a simple lookup rather than long division.

Binary: what the machine actually stores

Every value a computer holds - an integer, a character, a pixel color - is ultimately binary. You rarely write binary literals by hand except when you're deliberately thinking in terms of individual bits: permission flags, feature flags packed into a single integer, or bitwise masks. 0b1010 makes it obvious at a glance which specific bits are set in a way 10 doesn't.

Hex: binary, compressed for humans

Hex is the default for anything that's conceptually "a pile of bytes" rather than "a quantity" - color values (#ff8800), memory addresses, hashes, UUIDs, MAC addresses. Two hex digits map exactly to one byte (0-255), which is why colors are written as three or four hex pairs instead of three decimal numbers separated by commas - it's a more compact, copy-pasteable representation of the exact same bytes.

Octal: why Unix permissions still use it

Octal has mostly fallen out of general use, but it persists in one specific place: Unix file permissions (chmod 755), because permissions are naturally three groups of exactly 3 bits each - read/write/execute for owner, group, and others - and one octal digit represents exactly one of those groups. It's a historical accident of the hardware Unix was originally built on (some early systems used 6-bit and 9-bit words, where octal was the natural fit), but the convention outlived the hardware.

Converting between bases

By hand, converting decimal to binary means repeated division by 2 and reading remainders bottom-up - tedious and error-prone past a handful of bits. Converting hex to binary is far easier since it's a fixed lookup table (each hex digit maps to exactly four binary digits), which is exactly why hex became the preferred human-facing shorthand for binary data in the first place, rather than octal or decimal.

255 (decimal) = 0xff (hex) = 0b11111111 (binary) = 0o377 (octal)

FAQ

Why do hex numbers use letters A-F?
Base 16 needs 16 distinct digits, but our numeral system only has 10 (0-9). The letters A through F stand in for the values 10 through 15.
Is 0x1A the same as 26?
Yes. 0x1A is hex notation for the same value that decimal writes as 26 - one hex digit "1" is 16, plus "A" (10), equals 26.
Does this handle negative numbers?
No - representing negative numbers in binary/hex depends on a bit-width and signedness convention (like two's complement) that varies by platform, so this kind of converter intentionally sticks to non-negative integers.

Browse all tools