What Are Number Bases? Binary, Decimal, Hex & Beyond
Every number you see is written in some base. Understand what that means and you'll unlock a fundamental concept behind how computers store data, display colors, and address memory.
Table of Contents
What is a Number Base?
A number base (also called a radix) is the number of unique digits a number system uses. The base determines how many symbols you have and what each position in a number is worth.
You already know base 10 — the decimal system— which uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. When you run out of digits, you carry over to the next position. The number "10" literally means "one group of ten, plus zero ones."
This same principle works for any base. In base 2 (binary), you only have two digits: 0 and 1. In base 16 (hexadecimal), you have sixteen: 0–9 plus A–F. The mechanics are identical — only the number of available digits changes.
Positional Notation: The Big Idea
The key insight behind all number bases is positional notation: the value of a digit depends on where it sits. Each position represents a power of the base:
In base B, the number d₃d₂d₁d₀ equals:
d₃ × B³ + d₂ × B² + d₁ × B¹ + d₀ × B⁰
Example in decimal (B=10):
4 7 2 5
= 4×10³ + 7×10² + 2×10¹ + 5×10⁰
= 4000 + 700 + 20 + 5
= 4725
Same idea in binary (B=2):
1 1 0 1
= 1×2³ + 1×2² + 0×2¹ + 1×2⁰
= 8 + 4 + 0 + 1
= 13 (decimal)This is not just a mathematical curiosity — it's the reason computers can work with numbers at all. Once you understand positional notation, every number base follows the same pattern.
The Four Bases That Matter in Computing
| Base | Name | Digits | Prefix | Used For |
|---|---|---|---|---|
| 2 | Binary | 0, 1 | 0b | How hardware actually works — transistors, logic gates, CPU instructions |
| 8 | Octal | 0–7 | 0o | Unix file permissions, legacy systems |
| 10 | Decimal | 0–9 | (none) | Everyday human counting, user-facing values |
| 16 | Hexadecimal | 0–9, A–F | 0x | Colors, memory addresses, byte values, MAC addresses |
To see how the same number looks in each base:
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 5 | 101 | 5 | 5 |
| 10 | 1010 | 12 | A |
| 42 | 101010 | 52 | 2A |
| 100 | 1100100 | 144 | 64 |
| 255 | 11111111 | 377 | FF |
| 1000 | 1111101000 | 1750 | 3E8 |
Notice how 255 is 11111111 in binary (eight 1s) and FFin hex — it's the maximum value that fits in one byte. This isn't a coincidence; it's why hex is so popular for representing byte values.
How to Convert Between Bases
Any Base → Decimal
Multiply each digit by its positional power of the base, then sum:
Binary 10110 → Decimal:
1×2⁴ + 0×2³ + 1×2² + 1×2¹ + 0×2⁰
= 16 + 0 + 4 + 2 + 0
= 22
Hex 2F → Decimal:
2×16¹ + F×16⁰
= 32 + 15
= 47
Octal 37 → Decimal:
3×8¹ + 7×8⁰
= 24 + 7
= 31Decimal → Any Base
Divide by the target base repeatedly and collect remainders (read bottom to top):
Convert 47 to binary:
47 ÷ 2 = 23 remainder 1 ↑
23 ÷ 2 = 11 remainder 1 ↑
11 ÷ 2 = 5 remainder 1 ↑ Read upward: 101111
5 ÷ 2 = 2 remainder 1 ↑
2 ÷ 2 = 1 remainder 0 ↑
1 ÷ 2 = 0 remainder 1 ↑
47 decimal = 101111 binary ✓
Convert 47 to hex:
47 ÷ 16 = 2 remainder 15 (F) ↑ Read upward: 2F
2 ÷ 16 = 0 remainder 2 ↑
47 decimal = 2F hex ✓Power-of-2 Shortcuts
When converting between bases that are powers of 2, you can skip decimal entirely:
- Binary ↔ Octal: Group binary digits by 3 (since 2³ = 8). Each group becomes one octal digit.
- Binary ↔ Hex: Group binary digits by 4 (since 2⁴ = 16). Each group becomes one hex digit.
- Octal ↔ Hex: Go through binary as an intermediate step — expand each octal digit to 3 bits, then regroup into 4-bit chunks for hex.
Binary to Hex (group by 4 from right):
1010 1111 0011
= A F 3
= 0xAF3
Binary to Octal (group by 3 from right):
101 011 110 011
= 5 3 6 3
= 0o5363Why Don't Computers Just Use Decimal?
If decimal is so intuitive to humans, why do computers use binary? The answer is physics:
- Transistors are binary by nature — A transistor is either on or off, conducting or not. Two states correspond perfectly to 1 and 0. Building reliable circuits with 10 distinct voltage levels would be far more complex and error-prone.
- Noise resistance — With only two states, it's easy to tell them apart even with electrical noise. With ten states, small voltage fluctuations could corrupt data.
- Boolean logic — Binary maps directly to true/false logic, which underpins all of computation (AND, OR, NOT gates).
- Simplicity scales — Simple binary circuits can be made incredibly small and fast, which is why modern CPUs pack billions of transistors.
We use hex and octal not because computers process them directly, but because they're compact, human-friendly representations of binary that align with how bytes and bits group together.
Unusual Bases You Might Encounter
Beyond the big four, a few other bases appear in specific contexts:
| Base | Name | Where You'll See It |
|---|---|---|
| 3 (ternary) | Ternary | Experimental ternary computers (e.g., Soviet Setun), balanced ternary in some algorithms |
| 12 (duodecimal) | Duodecimal | Time (12 hours), measurements (12 inches/foot, dozen) |
| 36 | Base-36 | URL shorteners, compact IDs (uses 0–9 and A–Z) |
| 58 | Base-58 | Bitcoin addresses (Base-36 minus confusing chars: 0/O, I/l) |
| 64 | Base-64 | Data encoding for email, data URIs, JWTs (uses A–Z, a–z, 0–9, +, /) |
Base Conversion in Code
JavaScript
// Decimal to other bases
(255).toString(2); // "11111111" (binary)
(255).toString(8); // "377" (octal)
(255).toString(16); // "ff" (hex)
(255).toString(36); // "73" (base-36)
// Other bases to decimal
parseInt("11111111", 2); // 255 (from binary)
parseInt("377", 8); // 255 (from octal)
parseInt("ff", 16); // 255 (from hex)
parseInt("73", 36); // 255 (from base-36)
// Literals in code
const bin = 0b11111111; // 255
const oct = 0o377; // 255
const hex = 0xFF; // 255Python
# Decimal to other bases
bin(255) # '0b11111111'
oct(255) # '0o377'
hex(255) # '0xff'
# Other bases to decimal
int("11111111", 2) # 255
int("377", 8) # 255
int("ff", 16) # 255
# Any base to any base (via decimal)
def convert_base(number_str, from_base, to_base):
decimal = int(number_str, from_base)
if to_base == 10:
return str(decimal)
digits = []
while decimal > 0:
digits.append("0123456789abcdefghijklmnopqrstuvwxyz"[decimal % to_base])
decimal //= to_base
return ''.join(reversed(digits)) or '0'C
#include <stdio.h>
int x = 255;
// Print in different bases
printf("Decimal: %d\n", x); // 255
printf("Octal: %o\n", x); // 377
printf("Hex: %x\n", x); // ff
printf("Hex: %X\n", x); // FF
// Literals
int bin = 0b11111111; // 255 (C23 / GCC extension)
int oct = 0377; // 255
int hex = 0xFF; // 255Real-World Applications
Here's where you'll actually encounter different bases in practice:
🎨 CSS Colors (Hex)
#FF5733 means Red=255, Green=87, Blue=51. Each pair of hex digits represents one byte (0–255) of a color channel.
🔐 File Permissions (Octal)
chmod 755 sets read/write/execute for owner, read/execute for everyone else. Each digit encodes 3 permission bits.
💾 Memory Addresses (Hex)
Debuggers and system tools show addresses like 0x7FFE1234ABCD. Hex is compact and aligns with byte boundaries.
📡 IP Addresses & Subnets (Binary)
Subnet masks like 255.255.255.0 make more sense as binary: 11111111.11111111.11111111.00000000 — twenty-four 1s followed by eight 0s.
🔗 Short URLs (Base-36/62)
URL shorteners encode large numeric IDs in base-36 or base-62 to produce compact strings like dQw4w9W.
Convert Between Any Number Base
Use our free Base Converter tool to instantly convert numbers between binary, octal, decimal, hexadecimal, and any base from 2 to 36 — right in your browser.
Try Base Converter →References
- Knuth, D.E. (1997). The Art of Computer Programming, Volume 2: Seminumerical Algorithms. Chapter 4.1: Positional Number Systems. Addison-Wesley Professional.
- Petzold, C. (2000). Code: The Hidden Language of Computer Hardware and Software. Microsoft Press.
- Mozilla Developer Network. Number.prototype.toString(). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString
- Python Software Foundation. Built-in Functions: int(). https://docs.python.org/3/library/functions.html#int
- IEEE Computer Society. IEEE 754-2019: Standard for Floating-Point Arithmetic. https://standards.ieee.org/ieee/754/6210/