Binary, Octal and Hexadecimal Numbers Explained Simply

By Deepak·

Computers don't count the way we do. Binary, octal, and hexadecimal are three different number systems — ways of writing values using different sets of digits. Once you see how they connect to each other, they stop being confusing and start feeling obvious.

What Binary, Octal and Hexadecimal Numbers Actually Mean

Every number system has a base — that's how many different digits it uses before it has to carry over to the next column.

  • Decimal (base 10) — what you use every day. Digits 0–9.
  • Binary (base 2) — only two digits: 0 and 1. Every computer stores data this way, because a transistor is either off (0) or on (1).
  • Octal (base 8) — digits 0–7. Useful in Unix file permissions and some older systems.
  • Hexadecimal (base 16) — digits 0–9, then A–F for ten through fifteen. Widely used in web colors, memory addresses, and encoding.

Think of each system as a different way to label the same number of objects. The quantity doesn't change — only the notation does.

How to Convert Between Number Bases (With Worked Examples)

Decimal to Binary

Take the decimal number 13. Repeatedly divide by 2 and note the remainders:

13 ÷ 2 = 6 remainder 1
 6 ÷ 2 = 3 remainder 0
 3 ÷ 2 = 1 remainder 1
 1 ÷ 2 = 0 remainder 1

Read remainders bottom to top: 1101

So decimal 13 = binary 1101. You can verify this in Python with a single line:

print(bin(13))   # Output: 0b1101
print(oct(13))   # Output: 0o15
print(hex(13))   # Output: 0xd

Python prefixes tell you the base at a glance: 0b = binary, 0o = octal, 0x = hexadecimal.

Decimal to Hexadecimal

Take 255 — the maximum value of a single byte. Divide by 16:

255 ÷ 16 = 15 remainder 15
 15 ÷ 16 =  0 remainder 15

15 in hex = F
Result: FF

That's why web colors like #FF0000 (pure red) look the way they do — each pair of hex digits represents one color channel (0–255).

Binary to Hexadecimal the Quick Way

Group binary digits into sets of four from the right. Each group of four bits maps directly to one hex digit — no division needed.

Binary:  1010 1111
Hex:        A    F
Result: 0xAF

This is why programmers prefer hex over raw binary. One hex digit replaces four bits, making long values much easier to read.

Quick Reference: The Same Values in All Four Bases

Decimal Binary Octal Hexadecimal
0000000
1000111
7011177
81000108
10101012A
15111117F
16100002010
25511111111377FF

Where Each Number Base Actually Shows Up

Binary is everywhere under the hood — CPU instructions, file storage, network protocols. You rarely write it by hand, but you read it when debugging hardware or bitwise operations.

Octal appears most often in Unix/Linux file permissions. The command chmod 755 sets permissions using octal: 7 = read+write+execute, 5 = read+execute. Also appears as escape sequences in some languages: \015 is octal for carriage return.

Hexadecimal is the most commonly written non-decimal base in everyday programming:

  • CSS colors: #3a86ff
  • Memory addresses in debuggers: 0x7ffd4a3c
  • Unicode code points: U+1F600
  • SHA-256 hashes, MAC addresses, IPv6 addresses

Need to convert hex to decimal (or any base) fast? Use the free hex to decimal converter — it handles all the bases in one place.

Common Gotchas With Number Bases

Leading zeros in octal. In older C code and some languages, a number starting with 0 is treated as octal, not decimal. Writing 010 gives you 8, not 10. This has caused real bugs in production code. Python 3 fixed this by requiring the 0o prefix explicitly.

Confusing hex letters with decimal digits. The value B3 in hex is 179 in decimal, not "B3" the string. Always confirm which base you're working in — especially when reading output from network tools or debuggers.

Signed vs. unsigned binary. Binary 11111111 is 255 if the number is unsigned (always positive), but -1 in an 8-bit signed system (using two's complement). The same bit pattern means different things depending on how the program interprets it.

Forgetting the prefix. When writing hex in code, always use the right prefix: 0x in most languages, # in CSS, &H in Visual Basic. Without it, the value gets read as decimal or throws an error.

How Binary, Octal and Hexadecimal Numbers Compare at a Glance

Base Digits used Best for Code prefix (most languages)
Binary (2)0, 1Bitwise ops, hardware0b
Octal (8)0–7Unix permissions0o
Hex (16)0–9, A–FColors, addresses, encoding0x
Decimal (10)0–9Human-readable output(none)

The MDN Web Docs have a thorough reference on how JavaScript handles number literals in different bases, including the exact prefix syntax.

Frequently Asked Questions About Binary, Octal and Hexadecimal Numbers

Why do computers use binary instead of decimal?

Computer hardware is built from transistors that switch between two states — on and off. It's far easier and more reliable to build circuits that represent two values (0 and 1) than ten. Binary maps directly onto that physical reality, which is why all digital data ultimately lives in base 2.

What is the difference between hexadecimal and binary?

Both represent the same data. Binary uses only 0s and 1s, so values get long quickly — the number 255 needs eight binary digits (11111111). Hexadecimal uses 16 symbols, so the same value is just FF — two characters. Hex is a compact, human-readable shorthand for binary data.

How do you convert binary to decimal by hand?

Write the binary number, then multiply each digit by 2 raised to its position (starting at 0 on the right). Add the results. For 1101: (1×8) + (1×4) + (0×2) + (1×1) = 8 + 4 + 0 + 1 = 13. Each position is a power of 2: 1, 2, 4, 8, 16, and so on.

Where is octal still used today?

Octal is mainly used in Unix and Linux file permissions (for example, chmod 644). It also appears as character escape sequences in C, Python, and some other languages. Outside of those contexts it's rare — hexadecimal has largely replaced it for most programming tasks.