/8 min read

What Are Number Bases? Binary, Decimal, Hex & Beyond

Every number you see is written in some base. Once you understand what that means, binary, octal, decimal, hexadecimal, colors, memory addresses, and file permissions all become much easier to read.

What is a Number Base?

A number base, also called a radix, is the number of unique digits a number system uses. The base controls which symbols are available and how much each position is worth.

Base 10, or decimal, uses ten digits: 0 through 9. When you run out of digits, you carry to the next position. The number 10 literally means one group of ten and zero ones.

The same idea works in any base. Binary has two digits, 0 and 1. Octal has eight digits, 0 through 7. Hexadecimal has sixteen digits, 0 through 9 plus A through F.

Positional Notation: The Big Idea

The key idea behind all number bases is positional notation: a digit's value depends on where it sits. Each position is a power of the base.

In base B, the number d3 d2 d1 d0 equals:

  d3 x B^3 + d2 x B^2 + d1 x B^1 + d0 x B^0

Example in decimal (B=10):
  4725 = 4x10^3 + 7x10^2 + 2x10^1 + 5x10^0
       = 4000   + 700    + 20     + 5
       = 4725

Same idea in binary (B=2):
  1101 = 1x2^3 + 1x2^2 + 0x2^1 + 1x2^0
       = 8     + 4     + 0     + 1
       = 13 decimal

Once that pattern clicks, every base conversion becomes the same idea with a different base value.

The Four Bases That Matter in Computing

BaseNameDigitsPrefixUsed For
2Binary0, 10bHardware states, bits, logic gates, CPU instructions
8Octal0-70oUnix permissions and older systems
10Decimal0-9(none)Everyday human counting and user-facing values
16Hexadecimal0-9, A-F0xColors, memory addresses, bytes, MAC addresses

Here is the same value written in several bases:

DecimalBinaryOctalHexadecimal
0000
510155
10101012A
42101010522A
100110010014464
25511111111377FF
1000111110100017503E8

Notice that 255 is 11111111 in binary and FF in hex. It is the maximum value that fits in one byte, which is why hex is so common for byte values.

How to Convert Between Bases

Any Base to Decimal

Multiply each digit by its positional power of the base, then add the results.

Binary 10110 -> Decimal:
  1x2^4 + 0x2^3 + 1x2^2 + 1x2^1 + 0x2^0
  = 16  + 0     + 4     + 2     + 0
  = 22

Hex 2F -> Decimal:
  2x16^1 + Fx16^0
  = 32   + 15
  = 47

Octal 37 -> Decimal:
  3x8^1 + 7x8^0
  = 24  + 7
  = 31

Decimal to Any Base

Divide by the target base repeatedly and collect remainders. Read the remainders from bottom to top.

Convert 47 to binary:
  47 / 2 = 23 remainder 1
  23 / 2 = 11 remainder 1
  11 / 2 =  5 remainder 1
   5 / 2 =  2 remainder 1
   2 / 2 =  1 remainder 0
   1 / 2 =  0 remainder 1

Read upward: 101111
47 decimal = 101111 binary

Convert 47 to hex:
  47 / 16 = 2 remainder 15 (F)
   2 / 16 = 0 remainder 2

Read upward: 2F
47 decimal = 2F hex

Power-of-2 Shortcuts

When converting between bases that are powers of 2, you can skip decimal and group binary digits directly.

  • Binary to octal: group binary digits by 3 because 2^3 = 8.
  • Binary to hex: group binary digits by 4 because 2^4 = 16.
  • Octal to hex: expand octal to binary, then regroup the bits into 4-bit chunks.
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
  = 0o5363

Why Do Computers Use Binary Instead of Decimal?

If decimal is natural for humans, why do computers use binary? The short answer is physics.

  • Transistors are naturally binary - they are on or off, conducting or not conducting.
  • Binary is noise resistant - two voltage ranges are easier to distinguish reliably than ten.
  • Boolean logic maps cleanly to binary - true/false operations become 1/0 circuits.
  • Simple circuits scale - small reliable binary circuits can be packed into chips by the billions.

Hex and octal are not how computers process data internally. They are compact, human-friendly ways to write binary patterns.

Unusual Bases You Might Encounter

Beyond the big four, a few other bases appear in specific contexts:

BaseNameWhere You Will See It
3TernaryExperimental ternary computers and balanced ternary algorithms
12DuodecimalTime, dozens, and measurements such as 12 inches per foot
36Base-36Compact IDs and URL shorteners using 0-9 and A-Z
58Base-58Bitcoin-style addresses that avoid confusing characters
64Base-64Data encoding for email, data URIs, JWTs, and binary-to-text formats

Base Conversion in Code

Most programming languages have built-in functions for common base conversions:

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
parseInt("377", 8);       // 255
parseInt("ff", 16);       // 255
parseInt("73", 36);       // 255

// Literals in code
const bin = 0b11111111;   // 255
const oct = 0o377;        // 255
const hex = 0xFF;         // 255

Python

# 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 = []
    alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"
    while decimal > 0:
        digits.append(alphabet[decimal % to_base])
        decimal //= to_base
    return ''.join(reversed(digits)) or '0'

C

#include <stdio.h>

int x = 255;

printf("Decimal: %d\n", x);  // 255
printf("Octal:   %o\n", x);  // 377
printf("Hex:     %x\n", x);  // ff
printf("Hex:     %X\n", x);  // FF

int bin = 0b11111111;  // 255 in C23 / GCC extension
int oct = 0377;        // 255
int hex = 0xFF;        // 255

Real-World Applications

Here is where different bases show up in everyday development work:

CSS Colors (Hex)

#FF5733 means red=255, green=87, blue=51. Each pair of hex digits is one color byte.

File Permissions (Octal)

chmod 755 sets read/write/execute for the owner and read/execute for group and others. Each digit encodes 3 permission bits.

Memory Addresses (Hex)

Debuggers and system tools show addresses like 0x7FFE1234ABCD because hex is compact and lines up with byte boundaries.

IP Addresses and Subnets (Binary)

Subnet masks are easier to understand in binary because the network prefix is a run of 1 bits followed by host 0 bits.

Short URLs (Base-36/Base-62)

URL shorteners encode large numeric IDs into compact strings such as dQw4w9W.

Convert Between Any Number Base

Use our free Base Converter tool to convert numbers between binary, octal, decimal, hexadecimal, and any base from 2 to 36 right in your browser.

Try Base Converter

References

  1. Knuth, D.E. (1997). The Art of Computer Programming, Volume 2: Seminumerical Algorithms. Chapter 4.1: Positional Number Systems. Addison-Wesley Professional.
  2. Petzold, C. (2000). Code: The Hidden Language of Computer Hardware and Software. Microsoft Press.
  3. Mozilla Developer Network. Number.prototype.toString(). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString
  4. Python Software Foundation. Built-in Functions: int(). https://docs.python.org/3/library/functions.html#int
  5. IEEE Computer Society. IEEE 754-2019: Standard for Floating-Point Arithmetic. https://standards.ieee.org/ieee/754/6210/
USTHJP