How to Convert Binary to Decimal (and Decimal to Binary)

Short answer
Write the powers of two (1, 2, 4, 8, 16β¦) under the binary digits from right to left, then add the values where there is a 1. For 101101: 32 + 8 + 4 + 1 = 45. To go from decimal to binary, divide by 2 repeatedly and read the remainders from bottom to top: 156 becomes 10011100.
Computers store everything as binary, using only the digits 0 and 1. Converting between binary and the decimal numbers we use every day is a core skill in computer science classes, networking (subnet masks), electronics and programming. It looks intimidating at first, but it relies on one simple idea: place value.
Place value in decimal and binary
In decimal (base 10), each position is worth ten times the one to its right: ones, tens, hundreds, thousands. The number 345 means 3 Γ 100 + 4 Γ 10 + 5 Γ 1.
Binary (base 2) works the same way, but each position is worth twice the one to its right:
| Position (from right) | 8th | 7th | 6th | 5th | 4th | 3rd | 2nd | 1st |
|---|---|---|---|---|---|---|---|---|
| Power of 2 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Binary to decimal: step by step
Convert 101101:
- Write the place values under each digit, starting with 1 on the right: 32, 16, 8, 4, 2, 1.
- Line them up with the digits: 1 0 1 1 0 1.
- Add the place values where the digit is 1: 32 + 8 + 4 + 1.
- Result: 45.
More examples:
- 1010 = 8 + 2 = 10
- 11111111 = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255 (the largest value in one byte)
- 10000000 = 128
The doubling shortcut
For long binary numbers, you can also work from left to right: start at 0, and for each digit, double your running total and add the digit. For 101101: 0β1β2β5β11β22β45. This avoids writing out the powers of two and is how many programs do it.
Decimal to binary: step by step
The most reliable method is repeated division by 2. Convert 156:
| Division | Quotient | Remainder |
|---|---|---|
| 156 Γ· 2 | 78 | 0 |
| 78 Γ· 2 | 39 | 0 |
| 39 Γ· 2 | 19 | 1 |
| 19 Γ· 2 | 9 | 1 |
| 9 Γ· 2 | 4 | 1 |
| 4 Γ· 2 | 2 | 0 |
| 2 Γ· 2 | 1 | 0 |
| 1 Γ· 2 | 0 | 1 |
Read the remainders from the bottom up: 10011100. Check: 128 + 16 + 8 + 4 = 156.
The subtraction method
Alternatively, find the largest power of two that fits, subtract it and repeat. For 2026: 1024 fits (remainder 1002), then 512 (490), 256 (234), 128 (106), 64 (42), 32 (10), 8 (2), 2 (0). Put a 1 in those positions and 0 elsewhere: 2026 = 11111101010.
Powers of two worth memorising
| Power | Value | Where you see it |
|---|---|---|
| 24 | 16 | Values in one hex digit |
| 28 | 256 | Values in one byte (0β255) |
| 210 | 1,024 | One kibibyte |
| 216 | 65,536 | Values in 16 bits |
| 232 | 4,294,967,296 | Values in 32 bits (IPv4 addresses) |
Binary fractions
Digits after the binary point are worth Β½, ΒΌ, β and so on. So 1011.101 = 8 + 2 + 1 + 0.5 + 0.125 = 11.625. Some simple decimal fractions, such as 0.1, have no exact binary representation, which is why computers sometimes show results like 0.1 + 0.2 = 0.30000000000000004.
Binary and hexadecimal
Every group of four binary digits maps to one hexadecimal digit, which is why programmers prefer hex for writing binary data compactly. 1001 1100 = 9C in hex = 156 in decimal. Colour codes are a familiar example; see how to convert HEX to RGB. Base64 is built on the same idea, regrouping bits into 6-bit chunks, as explained in what Base64 encoding is.
A real use: reading subnet masks
Network settings are a common place to meet binary. An IPv4 subnet mask such as 255.255.255.0 is four bytes, and each 255 is 11111111 in binary. Written out, the mask is 11111111.11111111.11111111.00000000: twenty-four 1s followed by eight 0s. That is why the same mask is also written as β/24β. A mask of 255.255.255.192 ends in 11000000 (128 + 64 = 192), so it has 26 ones and is written /26. Once you can convert a byte, these settings make sense.
Check your answers instantly
The binary, hex and decimal converter converts between binary, octal, decimal, hexadecimal and base 36, including very large numbers and negative values. It is ideal for checking homework or working with subnet masks. For other kinds of conversion, try the Roman numeral converter or the unit converter, and see our unit conversion cheat sheet.
Common mistakes
- Reading the division remainders from top to bottom instead of bottom to top.
- Starting the place values at 2 instead of 1 on the right.
- Losing track of zeros in the middle of a number; every position counts.
- Confusing binary 10 (two) with decimal 10 (ten). Writing a subscript, such as 102, or the prefix 0b (0b10) removes the doubt.
Frequently asked questions
How do you convert binary to decimal?
Multiply each binary digit by its place value (1, 2, 4, 8, 16β¦ from the right) and add the results. 101101 = 32 + 8 + 4 + 1 = 45.
How do you convert decimal to binary?
Divide by 2 repeatedly, writing down each remainder, until you reach 0. Read the remainders from the last to the first.
What is 255 in binary?
11111111, which is eight 1s. It is the largest number that fits in one byte.
Why do computers use binary?
Electronic circuits can reliably represent two states, such as on and off or high and low voltage, which map naturally to 1 and 0.
How do I convert binary to hexadecimal?
Split the binary number into groups of four digits from the right and convert each group to one hex digit. 10011100 = 1001 1100 = 9C.