What Is a Number Base? Binary, Octal, and Hex Basics Made Simple
In computing, you constantly meet not just decimal but binary, octal, and hexadecimal "number bases." This article explains, for beginners, what a number base is, why computers use binary, the 0b/0o/0x notation, how to convert to and from decimal, the relationship between bits and bytes, and why hex is preferred for things like color codes.
While writing programs, you run into numbers with unfamiliar prefixes such as "0b1010," "0o17," and "0xFF." These are all numbers written in a number base different from the decimal we use every day. They may look confusing, but once you understand the mechanism, each is simply a "different way of writing numbers." This article explains, step by step, what a number base is, why computers use binary, and how to convert between the various bases.
What Is a Number Base
A number base (also called radix) is the value that tells you "how many digits are used and at what point a column carries over" when writing numbers. The numbers we use daily employ ten digits, 0 through 9, and carry over after 9. This is decimal (base 10).
For example, the decimal number "253" can be seen as each digit carrying a weight that is a power of 10.
253 = 2×10² + 5×10¹ + 3×10⁰
Replacing that "10" with another number gives you the other bases. In base 2 the usable digits are just 0 and 1; in base 8 they are 0–7; in base 16 they are 0–9 plus A–F. In every base, the idea that "each digit carries a weight that is a power of the base" stays the same, and once you grasp this, conversion is not hard.
The same number looks completely different depending on the base. If you want to compare a few numbers side by side, the Number Base Converter shows the binary, octal, and hex notations at once, so the correspondence becomes intuitive.
Why Computers Use Binary
Computers use binary (base 2) internally because "two states" are the easiest thing for electronic circuits to handle. Whether the voltage is high or low, whether a switch is on or off, whether current flows or not—these two-choice states can be distinguished reliably in a circuit. By mapping them to 0 and 1, all information can be represented as electrical states.
If you tried to handle decimal directly in a circuit, you would need to distinguish ten voltage levels for 0 through 9 accurately. That is fragile against noise and degradation, and far harder to design. With only two states, it is easy to judge "high or low" even with some noise, keeping circuits simple and highly reliable.
The binary "1011" represents the decimal 1×8 + 0×4 + 1×2 + 1×1 = 11.
So although binary uses more digits, it can represent any number with just 0 and 1. Not only numbers but also text, images, audio, and even programs themselves—every kind of data a computer handles ultimately comes down to this sequence of 0s and 1s. Binary is, in effect, the computer's native language.
How Each Base Is Written: 0b, 0o, 0x
The same string "10" means something completely different depending on whether it is binary or decimal. So many programming languages add a prefix to the front of a number to indicate its base.
| Base | Name | Prefix | Usable digits | Example (decimal 255) |
|---|---|---|---|---|
| 2 | Binary | 0b | 0, 1 | 0b11111111 |
| 8 | Octal | 0o | 0–7 | 0o377 |
| 10 | Decimal | (none) | 0–9 | 255 |
| 16 | Hexadecimal | 0x | 0–9, A–F | 0xFF |
0b comes from binary, 0o from octal, and 0x from hexadecimal. For instance, writing "0xFF" makes it clear at a glance that it is hex FF (decimal 255). In hex, the digits after 9 are A, B, C, D, E, F, with F corresponding to decimal 15.
Prefixes differ slightly by language. In older languages such as C, octal could be written with just a leading 0, like "0377," which means the same as "0o377." To avoid misreading, many modern languages recommend the explicit 0o form.
Converting to and from Decimal
Base conversion can be done by hand once you know the principle. Let us look at the basic procedure using decimal-binary conversion as an example.
Decimal → Binary (division method)
The basic approach is to keep dividing the decimal number by 2 and read the remainders from bottom to top. Let us convert decimal 13 to binary.
- 13 ÷ 2 = 6 remainder 1
- 6 ÷ 2 = 3 remainder 0
- 3 ÷ 2 = 1 remainder 1
- 1 ÷ 2 = 0 remainder 1
Reading the remainders from the bottom gives "1101." So decimal 13 is 1101 in binary.
Binary → Decimal (weighting method)
The reverse conversion multiplies each digit by "a power-of-the-base weight" and sums them. For binary 1101:
1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 8 + 4 + 0 + 1 = 13
The idea is the same for octal and hex; you just replace the divisor (or the weight) with 8 or 16. With practice you can do it in your head, but mistakes become easy as the number of digits grows. To check results or convert large numbers, the Number Base Converter instantly converts your input to binary, octal, decimal, and hex with confidence.
The Relationship Between Bits and Bytes
A single binary digit—either 0 or 1—is the smallest unit, called a bit. One bit can represent two pieces of information: "on/off" or "true/false." As bits increase, the number of representable combinations doubles each time; n bits can represent 2 to the n values.
A byte is the unit that groups eight bits together. With 8 bits you get 2 to the 8th = 256 combinations, that is, values from 0 to 255. This is the basic unit for counting data size in computers, and KB (kilobyte) and MB (megabyte) are all based on the byte.
| Unit | Bits | Number of values |
|---|---|---|
| 1 bit | 1 | 2 (0–1) |
| 1 byte (8 bits) | 8 | 256 (0–255) |
| 2 bytes | 16 | 65,536 |
It is also important that one byte (8 bits) can be written as exactly two hex digits (00–FF). Because 8 bits map neatly onto two hex digits, hex is preferred when handling memory contents and byte sequences. This correspondence leads to the usefulness of hex explained next.
Why Hexadecimal Is Used
Hexadecimal (base 16) is prized in programming because it pairs extremely well with binary while keeping the digit count short. Since 16 is 2 to the 4th, four binary digits correspond to exactly one hex digit.
Binary 1111 1111 → Hex FF (decimal 255)
Thanks to this property, you can easily convert lengthy binary into hex just by mechanically splitting it into groups of four digits, and vice versa. For humans, "00" is far easier to read than "00000000," and "FF" than "11111111," reducing transcription mistakes.
A familiar example is web color codes. "#FF0000" is red, "#00FF00" is green, and "#0000FF" is blue; these specify the strength of red, green, and blue each as one byte (two hex digits, 0–255). Using hex, the three color values are compactly expressed in just six characters. Hex also shines in displaying memory addresses, character codes, and inspecting binary data (dumps)—in every scene where you peek inside a computer.
As you can see, knowledge of number bases is useful in a wide range of situations, from specifying colors to analyzing data. Start by using the Number Base Converter to compare how the same number is written in binary, octal, and hex. Getting hands-on with the correspondence is the fastest way to understand number bases.
Please note that this article is intended to provide general information. Because notation and specifications differ in detail across programming languages, make your decision in actual development after checking the latest official documentation.
FAQ
What is a number base?
A number base is the value that indicates how many digits are used and at what point a column carries over when writing numbers. Everyday decimal uses ten digits (0–9) and is base 10, while binary uses two digits (0 and 1) and is base 2. In every base, the idea that each digit carries a weight that is a power of the base stays the same.
Why do computers use binary?
Because electronic circuits can most reliably distinguish "two states" such as on/off or high/low voltage. By mapping them to 0 and 1, any information can be represented with noise-resistant, simple circuits. Not just numbers but text, images, audio, and programs all end up as sequences of 0s and 1s.
What do 0b, 0o, and 0x mean?
They are prefixes that distinguish a number's base. 0b means binary, 0o means octal, and 0x means hexadecimal. For example, 0xFF is hex FF, which equals decimal 255. A number with no prefix is normally treated as decimal.
How do I convert a decimal number to binary?
The basic approach is the division method: keep dividing by 2 and read the remainders from the bottom. For 13, you get 13÷2=6 r1, 6÷2=3 r0, 3÷2=1 r1, 1÷2=0 r1, which reads as 1101 from the bottom. To go back from binary to decimal, multiply each digit by its power-of-2 weight and sum them.
Are the values I enter in the Number Base Converter sent to a server?
WAZA TOOLS' Number Base Converter runs entirely in your browser, so the values you enter are never sent to or stored on a server. It works on smartphones too, and you can convert between binary, octal, decimal, and hex as many times as you like, for free.