Binary to decimal usually comes first in a computer science course, since it is just addition once you know the positional weights. Decimal to binary is the harder direction to do in your head. Given the number 13, how do you work out that it is 1101 in binary without a calculator? Repeated division by 2 is the standard answer, and it becomes close to automatic after a handful of tries.
This page covers two methods: repeated division by 2, which works on any whole number, and a subtraction shortcut some people find more intuitive for values under 16. Both land on the same answer.
Repeated Division by 2
The algorithm is simple. Divide the number by 2. Write down the remainder (always 0 or 1). Divide the quotient by 2. Write down that remainder. Keep going until the quotient reaches 0. Then read the remainders from bottom to top. That sequence of 0s and 1s is the binary representation.
The reason you read bottom to top: the first division you perform gives you the least significant bit (the rightmost one). The last division gives you the most significant bit (the leftmost one). Reading your remainder list from bottom to top puts the most significant bit on the left, which is the standard way binary is written.
First Pass: Converting 13
Start with 13 and divide by 2 at each step:
| Step | Dividend | Divide by 2 | Quotient | Remainder |
|---|---|---|---|---|
| 1 | 13 | 13 / 2 | 6 | 1 |
| 2 | 6 | 6 / 2 | 3 | 0 |
| 3 | 3 | 3 / 2 | 1 | 1 |
| 4 | 1 | 1 / 2 | 0 | 1 |
Remainders collected top to bottom: 1, 0, 1, 1. Read from bottom to top: 1101. Check: 8 + 4 + 0 + 1 = 13. Correct.
A Bigger Number: Converting 200
A larger number shows that the method scales without any changes:
| Step | Dividend | Quotient | Remainder |
|---|---|---|---|
| 1 | 200 | 100 | 0 |
| 2 | 100 | 50 | 0 |
| 3 | 50 | 25 | 0 |
| 4 | 25 | 12 | 1 |
| 5 | 12 | 6 | 0 |
| 6 | 6 | 3 | 0 |
| 7 | 3 | 1 | 1 |
| 8 | 1 | 0 | 1 |
Remainders bottom to top: 1, 1, 0, 0, 1, 0, 0, 0 = 11001000. Verify: 128 + 64 + 0 + 0 + 8 + 0 + 0 + 0 = 200. Eight steps for an 8-bit number, which makes sense: 200 fits in a byte, so it takes exactly 8 divisions.
The Subtraction Method
An alternative that some people find quicker for numbers under 128. Instead of dividing, you subtract powers of 2 from largest to smallest.
Start with the largest power of 2 that fits into your number. Write a 1 for that position. Subtract it and repeat with the remainder. If a power of 2 does not fit, write a 0 for that position and move to the next smaller power.
Convert 13 using subtraction:
- Largest power of 2 fitting in 13 is 8 (23). Write 1. Remainder: 13 - 8 = 5.
- Next power is 4 (22). Fits in 5. Write 1. Remainder: 5 - 4 = 1.
- Next power is 2 (21). Does not fit in 1. Write 0.
- Next power is 1 (20). Fits in 1. Write 1. Remainder: 0. Done.
Result: 1101. Same answer. For values under 16, the subtraction method is fast because you only need to check four powers of 2. For anything above 64 or so, most people find the division steps easier to track on paper.
Quick Reference: 0 to 15
The first 16 values come up constantly. Worth having on hand:
| Decimal | Binary | Decimal | Binary |
|---|---|---|---|
| 0 | 0000 | 8 | 1000 |
| 1 | 0001 | 9 | 1001 |
| 2 | 0010 | 10 | 1010 |
| 3 | 0011 | 11 | 1011 |
| 4 | 0100 | 12 | 1100 |
| 5 | 0101 | 13 | 1101 |
| 6 | 0110 | 14 | 1110 |
| 7 | 0111 | 15 | 1111 |
These pairs match rows 0 to 15 of binary-ascii-reference-2026.csv, truncated to 4 bits since none of them need the top half of a byte.
Padding to 8 Bits
The number 13 converts to 1101, which is 4 bits. In most computing contexts, values are stored in whole bytes. A byte is 8 bits, so the 4-bit result needs four leading zeros: 00001101. The value is identical; the padding just makes the byte boundary visible.
When does this matter? Whenever binary data is transmitted, stored in a fixed-width field, or fed to a function expecting a fixed-length input. An IPv4 octet is always exactly 8 bits. A byte in a file is always 8 bits. RGB colour channels are always 8 bits. Dropping the padding is fine for a quick calculation, but a computer storing the value in a byte register will include those zeros whether you write them or not.
Padding rule: count the bits in your result, subtract from 8 (or 16, or 32, depending on the target word size), and prepend that many zeros.
Real-World Uses
Two places where decimal-to-binary conversion comes up in practice:
IPv4 subnets. The subnet mask 255.255.255.0 is four bytes, all of which convert to binary to show which bits of an address are the network portion. A mask of 255.255.255.128 has a fourth byte of 128, which is 10000000 in binary. That single leading 1 halves the subnet: 126 usable host addresses instead of 254. Network engineers do this conversion regularly when designing address plans.
Unix file permissions with chmod. The command chmod 644 file.txt sets owner to 6, group to 4, others to 4. Each digit is a 3-bit binary number. 6 is 110 (read + write, no execute). 4 is 100 (read only). 7 would be 111 (all three). The numeric mode is just the decimal representation of the 3-bit permission flags.
The division method handles both cases. For the subnet mask, convert each octet separately. For chmod, you are converting a single digit at a time, which the quick-look table above makes trivial.
For the reverse operation, see binary to decimal conversion. If you are just starting out and want to understand what binary numbers are and how to read them, the how to read binary numbers guide is a good starting point.
FAQ
Why do you read the remainders bottom to top in the division method?
Each remainder you collect is the next bit going from the least significant (rightmost) to the most significant (leftmost). The first division produces the rightmost bit; the last division produces the leftmost bit. Reading the list from bottom to top reverses that order so the most significant bit lands on the left, which is the standard way binary numbers are written.
How do you convert a decimal number larger than 255 to binary?
The repeated division method has no upper limit. Keep dividing by 2 and collecting remainders until the quotient reaches 0. For example, 200 requires eight divisions and produces the 8-bit result 11001000. Numbers above 255 simply need more than 8 bits: 256 itself is 100000000, a 9-bit number. 65,535 needs 16 bits; 4,294,967,295 needs 32 bits.
What does it mean to pad a binary number to 8 bits?
Padding means adding leading zeros on the left until the number has exactly 8 digits. The number 13 in binary is 1101 (4 bits). Padded to 8 bits it becomes 00001101. The value is identical; the extra zeros just make the byte boundary explicit, which matters when binary data is stored or transmitted in fixed-width fields.
Can the subtraction method handle any number the division method can?
Yes, both methods work on any non-negative whole number. The subtraction method tends to be faster for small numbers under 16 because the weight table is short. For larger numbers, most people find repeated division easier because you only need to divide by 2 at each step rather than identifying the right power of 2 to subtract.
What is the largest number this page's converter will accept?
4,294,967,295, which is 32 bits of binary (2 to the power of 32, minus 1). That covers everything from a single chmod digit to a full IPv4 address.
