Understanding Number Bases
A number base, or radix, defines how many unique digits a numeral system uses to represent numbers. The base we use in everyday life is decimal (base-10), which has ten digits: 0 through 9. Computers, however, operate in binary (base-2), using only the digits 0 and 1. Between these two extremes lie octal (base-8) and hexadecimal (base-16), which serve as convenient shorthand representations of binary data.
The concept of number bases is fundamental to computer science, digital electronics, and software engineering. Whether you are debugging a memory dump, configuring network settings, working with color codes, or studying digital logic, you will encounter multiple number bases on a regular basis. This guide will teach you how to convert confidently between binary, octal, decimal, and hexadecimal.
The Four Essential Number Bases
Binary (Base-2)
Binary is the language of computers. Every piece of data stored in a computer's memory is represented as a sequence of bits, each of which can be either 0 or 1. A group of 8 bits is called a byte and can represent 256 different values (0 to 255). Binary numbers are prefixed with 0b in many programming languages, so 0b1010 means the binary number 1010.
While binary is precise, it is verbose. The decimal number 255, for instance, requires 8 binary digits: 11111111. As numbers grow larger, binary representations become increasingly difficult for humans to read and work with, which is why octal and hexadecimal exist as more compact alternatives.
Octal (Base-8)
Octal uses eight digits (0 through 7) and was historically important in computing because early systems used word sizes that were multiples of 3 bits (6-bit, 12-bit, 18-bit, 36-bit). Octal groups binary digits into sets of three, making it a natural shorthand for these architectures. The prefix 0o is used in Python, while older systems sometimes used a leading zero (e.g., 0777 for Unix file permissions).
Today, octal is most commonly encountered in Unix and Linux file permissions. When you see chmod 755, the numbers 7, 5, and 5 are octal digits representing read, write, and execute permissions for the owner, group, and others respectively.
Decimal (Base-10)
Decimal is the number system we use every day. It has ten digits (0 through 9) and each position represents a power of 10. While decimal is intuitive for humans, it does not map neatly to binary representation, which is why conversions between decimal and binary (or hex) require explicit calculation rather than simple grouping.
Hexadecimal (Base-16)
Hexadecimal uses sixteen symbols: the digits 0 through 9 and the letters A through F (where A=10, B=11, C=12, D=13, E=14, F=15). Each hex digit corresponds to exactly 4 binary bits, making it an ideal compact representation for byte-oriented data. A single byte (8 bits) is represented by exactly 2 hex digits, ranging from 00 to FF.
Hexadecimal is ubiquitous in computing. You will encounter it in HTML color codes (#8B5CF6), memory addresses (0x7FFF0010), Unicode code points (U+1F600), MAC addresses (00:1A:2B:3C:4D:5E), and countless other contexts. The prefix 0x is standard in most programming languages.
Conversion Methods and Examples
Binary to Decimal
Multiply each binary digit by 2 raised to the power of its position (starting from 0 on the right) and sum all the results. This is called the positional notation method.
Example: Convert 110101 to decimal
Position: 5 4 3 2 1 0
Bit: 1 1 0 1 0 1
Value: 1×2⁵ + 1×2⁴ + 0×2³ + 1×2² + 0×2¹ + 1×2⁰
= 32 + 16 + 0 + 4 + 0 + 1
= 53
Decimal to Binary
Repeatedly divide the decimal number by 2, recording the remainder at each step. The binary representation is the remainders read from bottom to top.
Example: Convert 53 to binary 53 ÷ 2 = 26 remainder 1 26 ÷ 2 = 13 remainder 0 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: 110101
Binary to Hexadecimal
Group the binary digits from right to left into sets of four, then convert each group to its hex equivalent.
Example: Convert 11010110 to hex Binary: 1101 0110 Decimal: 13 6 Hex: D 6 Result: 0xD6
Hexadecimal to Binary
Replace each hex digit with its 4-bit binary equivalent.
Example: Convert 0x8B5CF6 to binary 8 → 1000 B → 1011 5 → 0101 C → 1100 F → 1111 6 → 0110 Result: 100010110101110011110110
Decimal to Hexadecimal
Repeatedly divide by 16, recording remainders. For remainders 10-15, use letters A-F.
Example: Convert 255 to hexadecimal 255 ÷ 16 = 15 remainder 15 → F 15 ÷ 16 = 0 remainder 15 → F Read bottom to top: FF
Octal to Binary and Back
Octal converts to binary by replacing each octal digit with its 3-bit equivalent. To go from binary to octal, group bits in sets of three from right to left.
Octal 755 → Binary: 111 101 101 → 111101101 Binary 111101101 → Grouped: 111 101 101 → Octal: 755
Quick Reference Table
Here is a handy reference showing the same number in all four bases:
Decimal Binary Octal Hex 0 0000 0 0 1 0001 1 1 2 0010 2 2 3 0011 3 3 4 0100 4 4 5 0101 5 5 6 0110 6 6 7 0111 7 7 8 1000 10 8 9 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F 16 10000 20 10 255 11111111 377 FF
Real-World Applications
HTML and CSS Color Codes
Every color used in web design is specified in hexadecimal notation. The color #8B5CF6 represents three byte values: red=8B (139), green=5C (92), blue=F6 (246). Understanding hex-to-decimal conversion helps you manipulate colors programmatically and create dynamic color schemes.
Network Configuration
IP addresses, subnet masks, and MAC addresses all rely on number base conversions. A subnet mask of 255.255.255.0 in decimal is FFFFFF00 in hex and 11111111.11111111.11111111.00000000 in binary. Network engineers must be comfortable converting between these representations to design and troubleshoot networks.
Memory Addresses and Debugging
When debugging software, memory addresses are displayed in hexadecimal. A pointer value like 0x7FFE9A3B refers to a specific location in the computer's memory. Understanding hex notation is essential for reading stack traces, analyzing crash dumps, and working with low-level programming languages like C and assembly.
File Permissions in Linux
Unix file permissions use octal notation. The command chmod 644 file.txt sets the file permissions to read/write for the owner (6=110 in binary=rw-) and read-only for the group and others (4=100 in binary=r--). Converting between octal and binary makes it easy to understand and calculate permission values.
Programming Examples
JavaScript
// Decimal to other bases
(255).toString(2) // "11111111" (binary)
(255).toString(8) // "377" (octal)
(255).toString(16) // "ff" (hex)
// Other bases to decimal
parseInt("11111111", 2) // 255
parseInt("377", 8) // 255
parseInt("ff", 16) // 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
Try Our Free Number Base Converter
Stop doing manual conversions. Our free online number base converter supports binary, octal, decimal, and hexadecimal with instant results. Type a number in any base and see it converted to all other bases simultaneously. The tool handles large numbers, validates your input, and works entirely in your browser with zero server-side processing.
Tips for Working with Number Bases
- Memorize the powers of 2 up to 2¹⁶. This makes binary-decimal conversions much faster since you can recognize bit patterns instantly.
- Learn the hex digit values by heart. Knowing that A=10, B=11, C=12, D=13, E=14, F=15 eliminates the need to look up conversions.
- Use grouping for quick binary-hex conversion. Every hex digit maps to exactly 4 binary bits, so you can convert visually without any arithmetic.
- Watch for prefix conventions. Different languages use different prefixes (0x, 0b, 0o, #, &H). Know which one you are working with to avoid misinterpretation.
- Verify your conversions. Always convert back to the original base to check your work, especially when working with large numbers or in high-stakes contexts like cryptographic key handling.
Conclusion
Number base conversion is one of the most practical skills in computing. Whether you are a web developer working with color codes, a sysadmin managing file permissions, a network engineer configuring subnets, or a student learning digital logic, the ability to convert fluently between binary, octal, decimal, and hexadecimal will save you time and prevent errors. With the methods, examples, and reference tables in this guide, you have everything you need to master number base conversions.
Frequently Asked Questions
How do I convert binary to decimal?
To convert binary to decimal, multiply each bit by its positional power of 2 (from right to left, starting at 2^0) and sum the results. For example, binary 1011 = (1×2³) + (0×2²) + (1×2¹) + (1×2⁰) = 8 + 0 + 2 + 1 = 11 in decimal.
What is hexadecimal used for?
Hexadecimal (base-16) is used extensively in computing to represent binary data compactly. Each hex digit represents exactly 4 binary bits, making it ideal for memory addresses, color codes (like #FF5733), MAC addresses, and debugging binary data. It is the standard notation in most programming languages for representing byte values.
Why do computers use binary?
Computers use binary (base-2) because digital circuits have two states: on and off, represented by 1 and 0. This binary system maps directly to the physical behavior of transistors, which act as electrical switches. All data in a computer—text, images, programs—is ultimately represented as sequences of binary digits.
What is the difference between octal and hexadecimal?
Octal (base-8) uses digits 0-7 and groups binary digits into sets of 3. Hexadecimal (base-16) uses digits 0-9 and letters A-F and groups binary digits into sets of 4. Hexadecimal is more common in modern computing because most systems use byte-based architectures where 4-bit grouping aligns naturally with 8-bit bytes.
Can I convert directly between any two bases?
Yes, you can convert between any two bases, but the process varies. For bases that are powers of 2 (binary, octal, hex), you can convert directly by grouping bits. For other bases (like decimal), you typically convert through decimal as an intermediate step: source base → decimal → target base. Our online converter handles all conversions instantly.