What is a Number Base?
A number base, also called a radix, defines how many unique digits a counting system uses before it rolls over to the next place value. The base you are most familiar with is base 10, which uses ten digits: 0 through 9. When you reach 9 and add one more, you carry over to the next column and get 10. This carry-over principle applies to every number base, whether it uses 2 digits, 8 digits, or 16.
In a positional number system, each digit's value depends on its position. In base 10, the number 352 means (3 x 100) + (5 x 10) + (2 x 1), or equivalently (3 x 102) + (5 x 101) + (2 x 100). The same positional logic applies in any base. In base 2, the number 1011 means (1 x 8) + (0 x 4) + (1 x 2) + (1 x 1) = 11 in decimal.
Understanding number bases is essential for programming because computers operate in binary, developers frequently encounter hexadecimal in debugging and design work, and octal appears in Unix file permissions. Each base exists because it solves a specific problem efficiently.
Decimal (Base 10)
Decimal is the number system humans use every day. It uses ten digits — 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 — and each position represents a power of ten. We almost certainly adopted base 10 because we have ten fingers, making it a natural counting system.
In programming, decimal is the default representation for integers and floating-point numbers. When you write let x = 42 in JavaScript or x = 42 in Python, you are writing a decimal literal. Most user-facing applications display numbers in decimal because it is what people expect and understand.
While decimal is intuitive for humans, it is not ideal for computers. The number 255 is simple enough in decimal, but in the binary world of transistors, it is far more natural to represent it as 11111111 (eight ones) or FF in hexadecimal. This mismatch between human-friendly and machine-friendly representations is why developers need to understand multiple number bases.
Binary (Base 2)
Binary is the foundation of all digital computing. It uses only two digits: 0 and 1. Each binary digit is called a bit, and a group of eight bits forms a byte. A single byte can represent values from 0 (00000000) to 255 (11111111), giving 256 possible values.
Computers use binary because their hardware is built from billions of transistors, which are tiny electronic switches that can only be on or off. There is no in-between state. Binary maps perfectly to this physical reality: 1 means on, 0 means off. Every piece of data in a computer — text, images, videos, programs — is ultimately stored and processed as sequences of ones and zeros.
In most programming languages, you can write binary literals with a 0b prefix:
// JavaScript let flags = 0b1010; // decimal 10 let mask = 0b11110000; // decimal 240 // Python permissions = 0b111101101 # decimal 493
Binary is particularly important for bitwise operations used in flags, permissions, network protocols, and low-level system programming. Operations like AND, OR, XOR, and bit shifting work directly on binary representations and are among the fastest operations a CPU can perform.
Hexadecimal (Base 16)
Hexadecimal, or hex, uses sixteen digits: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15). The critical property of hex is that each digit represents exactly four bits. This means one byte (eight bits) maps to exactly two hex digits, making hex a compact and convenient way to represent binary data.
You encounter hexadecimal constantly in web development and systems programming. CSS color codes like #FF5733 are three hex byte values: FF (255) for red, 57 (87) for green, and 33 (51) for blue. Memory addresses are displayed in hex because they can represent large values concisely: the address 0x7FFF5FBFF8A0 would be impractically long in binary or decimal.
Other common uses include MAC addresses (00:1A:2B:3C:4D:5E), Unicode code points (U+1F600), and encoding formats like Base16. In most languages, hex literals use a 0x prefix:
// JavaScript let color = 0xFF5733; // decimal 16734003 let address = 0x1A2B; // decimal 6699 // Python max_value = 0xFF # decimal 255
Octal (Base 8)
Octal uses eight digits: 0 through 7. Each octal digit represents exactly three bits, which makes it a natural fit for systems where data is organized in groups of three. While less common than hex in modern development, octal has one domain where it remains dominant: Unix file permissions.
In Unix and Linux, file permissions are assigned to three groups — owner, group, and others — with three permission types each: read (4), write (2), and execute (1). These values add up to a single octal digit per group. The permission 755 means the owner has read+write+execute (7), while the group and others have read+execute (5). In binary, this is 111 101 101, which shows exactly why octal is the perfect fit.
# Set file permissions using octal
chmod 644 myfile.txt # rw-r--r--
chmod 755 script.sh # rwxr-xr-x
// JavaScript octal literal (strict mode prefix)
let perm = 0o755; // decimal 493
// Python
os.chmod("file.txt", 0o644)
Octal was more widely used in early computing when systems had 12-bit, 24-bit, or 36-bit word sizes that divided evenly by three. As 8-bit bytes and 32/64-bit architectures became standard, hexadecimal largely replaced octal for general-purpose binary representation.
How to Convert Between Bases Manually
Decimal to binary: Repeatedly divide by 2 and record the remainders. Read the remainders from bottom to top. For example, to convert 13 to binary: 13 / 2 = 6 remainder 1, 6 / 2 = 3 remainder 0, 3 / 2 = 1 remainder 1, 1 / 2 = 0 remainder 1. Reading bottom to top gives 1101.
Binary to hex: Group the binary digits into sets of four from right to left, padding with leading zeros if needed. Convert each group to its hex digit. For example, 11010110 becomes 1101 0110, which is D6.
Hex to decimal: Multiply each digit by its place value (powers of 16) and sum the results. For 2F: (2 x 16) + (15 x 1) = 32 + 15 = 47.
Decimal to hex: Divide by 16 repeatedly and record remainders. To convert 255: 255 / 16 = 15 remainder 15 (F), 15 / 16 = 0 remainder 15 (F). Result: FF.
In practice, most developers rely on built-in language functions rather than manual conversion:
// JavaScript
(255).toString(16) // "ff"
(255).toString(2) // "11111111"
(255).toString(8) // "377"
parseInt("ff", 16) // 255
parseInt("11111111", 2) // 255
# Python
hex(255) # '0xff'
bin(255) # '0b11111111'
oct(255) # '0o377'
int("ff", 16) # 255
Real-World Examples in Programming
CSS colors and design: Every web developer works with hex color codes. The value #000000 is black (all channels zero), #FFFFFF is white (all channels at maximum 255), and #4F6EF7 is a specific shade of blue. Understanding that each pair of hex digits represents one byte (0-255) makes it easy to reason about color values and create variations.
Bitwise flags: Many APIs and protocols use binary flags to pack multiple boolean values into a single integer. A feature flag variable like 0b00001011 might mean features 1, 2, and 4 are enabled while feature 3 is disabled. Checking a specific flag uses the AND operator: flags & 0b00000100 tests whether the third bit is set.
Network programming: IP addresses, subnet masks, and port numbers all involve number base conversions. The subnet mask 255.255.255.0 is more intuitive in binary as 11111111.11111111.11111111.00000000, clearly showing which bits identify the network versus the host.
Debugging and memory inspection: Debuggers and hex editors display memory contents in hexadecimal because it provides a compact view of raw bytes. A hex dump like 48 65 6C 6C 6F is far more readable than its binary equivalent and directly translates to ASCII characters (spelling "Hello").
Cryptographic hashes: Hash values like SHA-256 are almost always displayed in hexadecimal. A 256-bit hash becomes a 64-character hex string instead of a 256-character binary string, making it practical to display and compare.
Try Our Number Base Converter
Convert between binary, decimal, hex, and octal instantly with our free online tool.
Open Number Base ConverterFrequently Asked Questions
- Why do computers use binary?
- Computers use binary because their hardware is built from transistors, which are electronic switches that can only be in one of two states: on or off. Binary (base 2) maps perfectly to this physical reality, with 1 representing on and 0 representing off. This makes binary the most reliable and efficient number system for digital electronics.
- What is hexadecimal used for?
- Hexadecimal (base 16) is used in programming for memory addresses, CSS color codes (like #FF5733), MAC addresses, error codes, and anywhere that binary data needs a compact human-readable representation. Each hex digit represents exactly four binary digits, making conversions between hex and binary straightforward.
- How do I convert decimal to binary?
- To convert decimal to binary, repeatedly divide the number by 2 and record the remainder at each step. Then read the remainders from bottom to top. For example, 13 divided by 2 gives 6 remainder 1, then 3 remainder 0, then 1 remainder 1, then 0 remainder 1. Reading bottom to top: 1101.
- What is base 10 in binary?
- The decimal number 10 in binary is 1010. To verify: (1 x 8) + (0 x 4) + (1 x 2) + (0 x 1) = 8 + 0 + 2 + 0 = 10.
- Why is hex used in color codes?
- Hex is used in color codes because each color channel (red, green, blue) uses one byte (0-255), which maps perfectly to two hexadecimal digits (00-FF). This gives a compact six-character representation like #FF5733 instead of the longer decimal equivalent rgb(255, 87, 51). Hex codes are also easy to read and manipulate once you understand the pattern.