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

Green binary digits on a dark screen beside server hardware
Photo: β€œFree binary code tech image” by rawpixel.com Β· CC0 1.0 Β· via Openverse (rawpixel)

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)8th7th6th5th4th3rd2nd1st
Power of 22726252423222120
Value1286432168421

Binary to decimal: step by step

Convert 101101:

  1. Write the place values under each digit, starting with 1 on the right: 32, 16, 8, 4, 2, 1.
  2. Line them up with the digits: 1 0 1 1 0 1.
  3. Add the place values where the digit is 1: 32 + 8 + 4 + 1.
  4. Result: 45.

More examples:

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:

DivisionQuotientRemainder
156 Γ· 2780
78 Γ· 2390
39 Γ· 2191
19 Γ· 291
9 Γ· 241
4 Γ· 220
2 Γ· 210
1 Γ· 201

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

PowerValueWhere you see it
2416Values in one hex digit
28256Values in one byte (0–255)
2101,024One kibibyte
21665,536Values in 16 bits
2324,294,967,296Values 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

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.