Dev Basics · 4 min read
Binary, Octal, and Hexadecimal Explained
Decimal is second nature, but programming constantly involves other bases — binary in the machine, hex in color codes and memory addresses, octal in file permissions. Once you see the pattern, they are all the same idea.
This guide explains what a base is and how to read the common ones.
Try it yourself with the related tool.
Convert number bases →Advertisement
What a base is
A number base is how many distinct digits a system uses. Decimal (base 10) uses 0–9. Binary (base 2) uses just 0 and 1, which maps directly to a computer's on/off bits. Each position is a power of the base, so in decimal the columns are 1, 10, 100; in binary they are 1, 2, 4, 8.
Why hexadecimal is everywhere
Binary is precise but long — a byte is eight digits. Because 16 is a power of 2, one hex digit represents exactly four binary bits, so a byte fits in two hex digits (00–FF). That tidy mapping is why colors like #FF8800, memory addresses, and hashes are written in hex.
Reading each base
Binary uses digits 0–1, often prefixed 0b. Octal uses 0–7, prefixed 0o, and shows up in Unix permissions. Hexadecimal uses 0–9 and A–F, prefixed 0x. The prefix tells you and the compiler how to interpret the digits.
Converting between them
To go from binary to decimal, multiply each bit by its power of two and add. In practice, a converter does this instantly and exactly, even for very large numbers where floating-point math would lose precision.
