Binary to Decimal — Convert Binary Numbers the Right Way
Binary to decimal conversion is foundational to understanding how computers store numbers. Here's the math, the algorithm, and how to convert in your head for small values.
Binary to decimal conversion is the process of reading a base-2 number (ones and zeros) and expressing it in the base-10 system humans use. Binary 1010 equals decimal 10. Binary 11111111 equals decimal 255 — the maximum value of one byte.
Use the Number Base Converter to convert between binary, decimal, hex, and octal instantly.
How binary numbers work
Every digit in a binary number represents a power of 2, starting from 2⁰ on the right:
Position: 7 6 5 4 3 2 1 0
Power: 2⁷ 2⁶ 2⁵ 2⁴ 2³ 2² 2¹ 2⁰
Value: 128 64 32 16 8 4 2 1
Each bit is either 0 (the power doesn’t contribute) or 1 (it does). The decimal value is the sum of all contributing powers.
The conversion algorithm
To convert binary to decimal, multiply each bit by its positional value and sum:
Binary: 1 0 1 1 0 1
│ │ │ │ │ └── × 2⁰ = × 1 = 1
│ │ │ │ └──── × 2¹ = × 2 = 0
│ │ │ └────── × 2² = × 4 = 4
│ │ └──────── × 2³ = × 8 = 8
│ └────────── × 2⁴ = × 16 = 0
└──────────── × 2⁵ = × 32 = 32
Sum = 32 + 0 + 8 + 4 + 0 + 1 = 45
Binary 101101 = decimal 45.
Common binary values to memorize
These appear constantly when working with networking, file permissions, and bit operations:
| Binary | Decimal | Context |
|---|---|---|
0000 0000 | 0 | Null byte |
0000 0001 | 1 | Lowest bit set |
0000 1111 | 15 | Low nibble mask |
1111 0000 | 240 | High nibble mask |
0111 1111 | 127 | Max positive int8 |
1000 0000 | 128 | Min negative int8 |
1111 1111 | 255 | Max uint8 / FF in hex |
0001 0000 0000 | 256 | 2⁸ |
1 0000 0000 | 256 | Same — leading 1 in 9th position |
How to convert in code
JavaScript
// Binary string to decimal integer:
const binary = '101101';
const decimal = parseInt(binary, 2);
console.log(decimal); // 45
// Decimal to binary string:
const dec = 45;
const bin = dec.toString(2);
console.log(bin); // "101101"
// Pad to 8 bits:
console.log(dec.toString(2).padStart(8, '0')); // "00101101"
Python
# Binary string to decimal:
binary = '101101'
decimal = int(binary, 2)
print(decimal) # 45
# Or using bin prefix:
decimal2 = int('0b101101', 2)
print(decimal2) # 45
# Decimal to binary string:
print(bin(45)) # '0b101101'
print(bin(45)[2:]) # '101101' (strip '0b' prefix)
print(f'{45:08b}') # '00101101' (8-bit padded)
Using the Number Base Converter
The Number Base Converter converts between all bases simultaneously:
- Select “Binary” as the input base
- Type or paste the binary number
- See the decimal (and hex, octal) output instantly
Signed vs unsigned binary
Standard binary is unsigned — the number is always positive. 11111111 = 255.
Two’s complement is how computers represent negative numbers in signed integer types. The most significant bit (MSB) is the sign bit:
- If MSB is 0, the number is positive (same as unsigned)
- If MSB is 1, the number is negative
To convert a negative two’s complement value:
- Flip all bits (one’s complement)
- Add 1
- The result is the magnitude; apply a negative sign
Two's complement: 1111 0011
Step 1 — flip: 0000 1100
Step 2 — add 1: 0000 1101 = 13
Result: -13
Signed 8-bit range: -128 to +127 Unsigned 8-bit range: 0 to 255
When you see a byte value like 0xFF or 11111111:
- As unsigned: 255
- As signed int8: -1
Context determines which interpretation is correct. In most low-level programming, you need to know the type to know the value.
Binary in networking
IP addresses and subnet masks are binary numbers displayed in decimal. An IPv4 address is 32 bits — four 8-bit groups (octets).
IP: 192.168.1.1
192 = 1100 0000
168 = 1010 1000
1 = 0000 0001
1 = 0000 0001
Binary: 11000000.10101000.00000001.00000001
A subnet mask like 255.255.255.0 in binary is 11111111.11111111.11111111.00000000. The 1s represent the network portion, 0s represent the host portion. This is why CIDR /24 means 24 bits for the network (three full octets of 255).
Binary in file permissions (Unix)
Unix file permissions use a 9-bit octal representation:
rwxrwxrwx → 111 111 111 → 777 (octal)
rwxr-xr-x → 111 101 101 → 755 (octal)
rw-r--r-- → 110 100 100 → 644 (octal)
Each group of 3 bits represents read (4), write (2), execute (1) for owner, group, others. Binary literacy makes permissions immediately readable.
Binary to hexadecimal shortcut
Every 4 binary digits = 1 hex digit. This is why programmers use hex as a compact binary notation:
Binary: 1010 1111 0011 0101
Group 4: 1010 | 1111 | 0011 | 0101
Hex: A | F | 3 | 5
Result: 0xAF35
To go the other direction, convert each hex digit to 4 binary digits:
0xB6 = 1011 0110
This shortcut only works cleanly for hex (base 16 = 2⁴). Octal uses 3-bit groups (8 = 2³).
Related tools
- Number Base Converter — convert between binary, decimal, hex, octal
- Decimal to Binary — the reverse conversion
- Hexadecimal Guide — hex as compact binary notation
Related posts
- Binary Arithmetic — Addition, Subtraction, and Two's Complement — Learn how computers perform binary arithmetic: binary addition with carry, two's…
- Binary to Text: How Binary Numbers Represent Characters — Binary to text conversion isn't magic — it's a lookup table. ASCII, Unicode, UTF…
- Bitmask and Bitwise Operations — Flags, Permissions, and Bit Manipulation — Bitmasks store multiple boolean flags in a single integer using bitwise AND, OR,…
- Decimal to Binary — How to Convert Numbers Between Bases — Decimal to binary, binary to decimal, hex to binary — number base conversion exp…
- Hexadecimal Explained — Why Programmers Use Hex and How to Read It — Hexadecimal (base-16) is used in programming for memory addresses, color codes, …
Related tool
Convert between binary, octal, decimal, hexadecimal, and text (UTF-8). Handles arbitrary lengths. Per-byte and per-character views.
Written by Mian Ali Khalid. Part of the Encoding & Crypto pillar.