Binary Numbers & Number Base Conversion: A Complete Guide (Binary, Decimal, Hex, Octal)
Binary is the foundation of everything your computer does. This guide walks through all four number bases, shows you how to convert between them by hand, explains why hex is everywhere in programming, and covers binary-to-text (ASCII) encoding.
What Is Binary?
Binary is a base-2 number system. It uses exactly two digits: 0 and 1. Every piece of data inside a computer — a character, an image, a network packet — is stored and processed as a sequence of these two values.
The reason computers use binary is physical: transistors inside a processor have two stable states, on and off. Representing those states as 1 and 0 is the most reliable way to store and transmit information without errors accumulating over billions of operations per second.
A single binary digit is called a bit. Eight bits make a byte. A byte can represent 256 different values (28 = 256), which is enough to encode any standard Latin character.
The Four Number Systems
Programmers regularly work with four bases. Each one is a shorthand for the same underlying binary data:
| Name | Base | Digits used | Common use |
|---|---|---|---|
| Binary | 2 | 0, 1 | CPU registers, bit flags, networking |
| Octal | 8 | 0–7 | Unix file permissions (chmod 755) |
| Decimal | 10 | 0–9 | Human-readable numbers, IP address octets |
| Hexadecimal | 16 | 0–9, A–F | Colors (#FF5500), memory addresses, hashes |
You can also use our number base converter to switch between all four bases instantly.
Binary to Decimal Conversion
Each position in a binary number represents a power of 2, starting at 20 = 1 on the right and doubling with each step to the left.
1×27 + 0×26 + 1×25 + 1×24 + 0×23 + 1×22 + 0×21 + 1×20= 128 + 0 + 32 + 16 + 0 + 4 + 0 + 1
= 181
A quick mental shortcut: write out the positional values (128, 64, 32, 16, 8, 4, 2, 1) above each bit, then add up only the positions where the bit is 1.
Positions with 1: 32, 8, 2
= 32 + 8 + 2 = 42
Decimal to Binary Conversion
The standard method is repeated division by 2. Divide the number, record the remainder, then divide the quotient again. Read the remainders from bottom to top.
45 ÷ 2 = 22 remainder 1
22 ÷ 2 = 11 remainder 0
11 ÷ 2 = 5 remainder 1
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1
Reading remainders bottom to top: 101101
Verify: 32 + 8 + 4 + 1 = 45. Correct.
An alternative is the subtraction method: find the largest power of 2 that fits, subtract it, mark a 1, repeat. Both methods give the same result.
Hexadecimal Explained
Hex is base 16. Because 16 = 24, every hex digit maps exactly to four binary bits (a nibble). This makes hex a compact, human-readable way to write binary data without losing precision.
The digits 10 through 15 are written as letters A through F:
| Decimal | Binary | Hex |
|---|---|---|
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
To convert hex to binary, replace each hex digit with its 4-bit binary equivalent:
3 = 0011, F = 1111
Result: 00111111
Why do developers use hex? Because a full byte (8 bits) fits in exactly two hex digits. A SHA-256 hash that would take 256 characters to write in binary takes only 64 in hex. Memory addresses, color codes, and checksums all benefit from this compression.
Binary to Text: ASCII Encoding
ASCII (American Standard Code for Information Interchange) assigns a number from 0 to 127 to each character in the English alphabet, plus digits, punctuation, and control codes. Since those numbers fit in 7 bits, standard ASCII characters are stored in one byte each.
When you see a block of binary and wonder what it says, the process is:
- Split the binary into 8-bit groups
- Convert each group from binary to decimal
- Look up that decimal value in the ASCII table
01001000 = 72 = H
01101001 = 105 = i
Result: "Hi"
Modern text uses UTF-8, which extends ASCII. For characters outside the basic ASCII range (accented letters, CJK characters, emoji), UTF-8 uses 2 to 4 bytes per character. The binary representation gets longer, but the decode logic is the same: convert bytes to code points, then look up the Unicode character.
Full Comparison Table: 0 to 15 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 |
Where You See These Number Systems in Practice
IP Addresses
An IPv4 address like 192.168.1.1 is four decimal numbers separated by dots. Each number is one byte (0–255), stored internally as 8 bits. The address 192.168.1.1 in binary is:
11000000.10101000.00000001.00000001
HTML Color Codes
The color #FF5500 is three hex pairs: FF (red = 255), 55 (green = 85), 00 (blue = 0). In binary that is 11111111 01010101 00000000 — three bytes, 24 bits total. This is why web colors are called 24-bit color.
Unix File Permissions
When you run chmod 755, the number 755 is octal. Each digit is 3 bits: 7 = 111 (read + write + execute), 5 = 101 (read + execute). So the full permission is:
111 101 101 = owner: rwx, group: r-x, others: r-x
Unicode Code Points
The emoji 😀 is Unicode code point U+1F600. In hex that is 1F600; in decimal it is 128512. UTF-8 encodes it as four bytes: F0 9F 98 80 in hex, or 11110000 10011111 10011000 10000000 in binary.
Convert Binary to Text Instantly
Paste binary code and decode it to readable text in one click. Supports ASCII, UTF-8, and hex input formats — no install needed.