Decimal to Binary Converter
Convert base-10 numbers to base-2 binary with the working shown
Decimal to binary: divide by 2 repeatedly and read the remainders from last to first. For example, 37 = 100101₂, 255 = 11111111₂ and 2026 = 11111101010₂.
How to convert decimal to binary
Every whole number can be written as a sum of distinct powers of two, and a binary number is simply a list of which powers are present: 1 for yes, 0 for no. The repeated-division method finds that list from the bottom up. Each time you divide by 2, the remainder tells you whether the current lowest power is used, and the quotient carries the rest of the number to the next step. It is the mirror image of the binary to decimal converter, and octal and hex sit alongside both on the number system converter.
Because the first remainder belongs to the ones place, the remainders come out in reverse order. The most common mistake is writing them top to bottom; always read them from the last remainder to the first. The converter shows each division, and you can check any answer by adding up the place values of its 1 bits.
Step by step
- Divide the decimal number by 2 and write down the remainder, which is 0 or 1.
- Divide the quotient by 2 again and record the new remainder.
- Repeat until the quotient reaches 0.
- Read the remainders from the last one to the first to get the binary number.
See the place values
Worked examples
A small number, a value near the top of one byte, and a four-digit year that needs 11 bits.
37 ÷ 2 = 18 r 1; 18 ÷ 2 = 9 r 0; 9 ÷ 2 = 4 r 1; 4 ÷ 2 = 2 r 0; 2 ÷ 2 = 1 r 0; 1 ÷ 2 = 0 r 1. Reading the remainders from bottom to top gives 100101₂.
= 100101₂
250 ÷ 2 = 125 r 0; 125 ÷ 2 = 62 r 1; 62 ÷ 2 = 31 r 0; 31 ÷ 2 = 15 r 1; 15 ÷ 2 = 7 r 1; 7 ÷ 2 = 3 r 1; 3 ÷ 2 = 1 r 1; 1 ÷ 2 = 0 r 1. Reading the remainders from bottom to top gives 11111010₂.
= 11111010₂
2026 ÷ 2 = 1013 r 0; 1013 ÷ 2 = 506 r 1; 506 ÷ 2 = 253 r 0; 253 ÷ 2 = 126 r 1; 126 ÷ 2 = 63 r 0; 63 ÷ 2 = 31 r 1; 31 ÷ 2 = 15 r 1; 15 ÷ 2 = 7 r 1; 7 ÷ 2 = 3 r 1; 3 ÷ 2 = 1 r 1; 1 ÷ 2 = 0 r 1. Reading the remainders from bottom to top gives 11111101010₂.
= 11111101010₂
How do I convert decimal to binary in Python or JavaScript?
In Python, bin(37) returns '0b100101' and format(37, "b") returns '100101'; in JavaScript, (37).toString(2) returns "100101".
Fixed widths need padding. Python's format(5, "08b") gives 00000101, and JavaScript's (5).toString(2).padStart(8, "0") does the same. Negative numbers need care: Python's bin(-5) returns '-0b101' rather than a two's complement pattern, so mask the value first with format(-5 & 0xFF, "08b") to get 11111011. In JavaScript, (-5 >>> 0).toString(2) returns the full 32-bit pattern, 11111111111111111111111111111011.
Other languages follow the same idea. Java has Integer.toBinaryString(37), C# has Convert.ToString(37, 2), and C++ can print a fixed-width pattern with std::bitset<8>(37).to_string(), which returns 00100101.
Spreadsheets have built-ins too. =DEC2BIN(A2) in Excel and Google Sheets handles −512 to 511, while =BASE(A2,2) covers larger non-negative numbers and takes an optional minimum length, so =BASE(37,2,8) returns 00100101.
How do you count in binary?
Count in binary by adding 1 to the rightmost bit and carrying whenever a column would reach 2: 0, 1, 10, 11, 100, 101, 110, 111, 1000.
It is the same rule as decimal counting, where 9 + 1 rolls over to 10, except that binary rolls over after 1. Two patterns make long sequences easy to check:
- The rightmost bit alternates 0, 1, 0, 1; the next bit changes every 2 counts, the next every 4, and bit n every 2n counts.
- Just before each power of two the number is all 1s: 111 (7) rolls over to 1000 (8), and 1111 (15) rolls over to 10000 (16).
A 4-bit counter wraps from 1111 back to 0000 after 16 steps, which is exactly how hardware counters and overflowing integers behave. Finger counting works the same way: with each finger as one bit, two hands count from 0 to 1,023.
Why do computers use binary instead of decimal?
Computers use binary because a transistor switch has two states that are easy to tell apart reliably, on and off, which map directly to 1 and 0.
Distinguishing ten voltage levels would leave much smaller margins between them, so electrical noise, heat and ageing parts would cause errors far more often. Two levels also match Boolean logic, where AND, OR and NOT gates combine true and false values, so arithmetic circuits can be built from very simple parts.
Decimal machines did exist. ENIAC, completed in 1945, counted in decimal with ring counters, and business computers long offered binary-coded decimal arithmetic for money, which survives in some processors and in the decimal formats of IEEE 754-2008. Today decimal is mostly a presentation layer: values are stored in binary and converted for people to read, which is also why memory comes in powers of two, as the MB to GB converter explains.
Decimal to binary conversion chart
Decimal numbers from 1 to 20, then round numbers and byte boundaries people look up most often. Every value is exact.
| Decimal (base 10) | Binary (base 2) |
|---|---|
| 1 | 1 |
| 2 | 10 |
| 3 | 11 |
| 4 | 100 |
| 5 | 101 |
| 6 | 110 |
| 7 | 111 |
| 8 | 1000 |
| 9 | 1001 |
| 10 | 1010 |
| 11 | 1011 |
| 12 | 1100 |
| 13 | 1101 |
| 14 | 1110 |
| 15 | 1111 |
| 16 | 10000 |
| 17 | 10001 |
| 18 | 10010 |
| 19 | 10011 |
| 20 | 10100 |
| 25 | 11001 |
| 30 | 11110 |
| 32 | 100000 |
| 40 | 101000 |
| 50 | 110010 |
| 64 | 1000000 |
| 75 | 1001011 |
| 99 | 1100011 |
| 100 | 1100100 |
| 128 | 10000000 |
| 150 | 10010110 |
| 200 | 11001000 |
| 250 | 11111010 |
| 255 | 11111111 |
| 256 | 100000000 |
| 500 | 111110100 |
| 1000 | 1111101000 |
Decimal vs binary: how do the two systems compare?
Decimal is the system people read; binary is the one digital hardware stores. The rows below show how the same values look and behave in each.
| Attribute | Decimal | Binary |
|---|---|---|
| Symbol | — | — |
| System | Base 10 | Base 2 |
| Defined as | digits 0–9 | digits 0–1 |
| Digits used | 0–9 | 0–1 |
| Value of the 5th place from the right | 10,000 (10⁴) | 16 (2⁴) |
| How 2026 is written | 2026 | 11111101010 |
| Largest value with 8 digits | 99,999,999 | 255 (11111111) |
| Where it is used | Human counting, prices, measurements | Transistor on/off states, memory addresses, network masks |
| Code prefix | None | 0b in Python, JavaScript, Java and C++ |
5 key differences
- Each extra decimal digit multiplies the range by 10, while each extra bit only doubles it.
- Every power of ten 10ⁿ ends in exactly n zeros in binary, because 10ⁿ = 2ⁿ × 5ⁿ; for example, 1,000 is 1111101000.
- Only decimal fractions whose reduced denominator is a power of two, such as 0.5, 0.25 and 0.375, have a finite binary form.
- A five-digit decimal number can need up to 17 bits, since 99,999 is larger than 2¹⁶ = 65,536.
- Binary-coded decimal (BCD) stores each decimal digit in its own 4-bit group, so 2026 becomes 0010 0000 0010 0110 instead of 11111101010.
How do you convert decimal to binary by subtracting powers of two?
Subtract the largest power of two that fits, write a 1 in that position, and repeat with what is left; every power that does not fit gets a 0. Knowing the powers of two (1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1,024 …) lets you build the number from the left this way. For 2,026:
- 2,026 − 1,024 = 1,002 → bit 10 is 1
- 1,002 − 512 = 490 → bit 9 is 1
- 490 − 256 = 234 → bit 8 is 1
- 234 − 128 = 106 → bit 7 is 1
- 106 − 64 = 42 → bit 6 is 1
- 42 − 32 = 10 → bit 5 is 1
- 16 does not fit into 10 → bit 4 is 0
- 10 − 8 = 2 → bit 3 is 1
- 4 does not fit into 2 → bit 2 is 0
- 2 − 2 = 0 → bit 1 is 1
- 1 does not fit into 0 → bit 0 is 0
Reading the bits from position 10 down to 0 gives 11111101010, the same answer the division method produces. This version is quicker in your head for numbers under a few thousand, while division is easier to do on paper for any size.
How many bits does a number need?
A number N needs ⌊log₂ N⌋ + 1 bits. So 1,000 needs 10 bits, because 2⁹ = 512 is too small and 2¹⁰ = 1,024 is enough. Signed ranges assume two's complement.
| Bits | Unsigned range | Signed range | Distinct values |
|---|---|---|---|
| 1 | 0 to 1 | −1 to 0 | 2 |
| 2 | 0 to 3 | −2 to 1 | 4 |
| 4 | 0 to 15 | −8 to 7 | 16 |
| 8 | 0 to 255 | −128 to 127 | 256 |
| 10 | 0 to 1,023 | −512 to 511 | 1,024 |
| 12 | 0 to 4,095 | −2,048 to 2,047 | 4,096 |
| 16 | 0 to 65,535 | −32,768 to 32,767 | 65,536 |
| 24 | 0 to 16,777,215 | −8,388,608 to 8,388,607 | 16,777,216 |
| 32 | 0 to 4,294,967,295 | −2,147,483,648 to 2,147,483,647 | 4,294,967,296 |
| 64 | 0 to 18,446,744,073,709,551,615 | −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 18,446,744,073,709,551,616 |
Negative decimals in 8-bit binary
Computers store negative integers in two's complement: write the positive value in binary, flip every bit and add 1. The result is the same as converting 256 minus the absolute value, shown in the last column.
| Decimal | 8-bit binary | Hex | Stored as unsigned |
|---|---|---|---|
| −1 | 11111111 | FF | 255 |
| −2 | 11111110 | FE | 254 |
| −5 | 11111011 | FB | 251 |
| −10 | 11110110 | F6 | 246 |
| −16 | 11110000 | F0 | 240 |
| −50 | 11001110 | CE | 206 |
| −64 | 11000000 | C0 | 192 |
| −100 | 10011100 | 9C | 156 |
| −127 | 10000001 | 81 | 129 |
| −128 | 10000000 | 80 | 128 |
How do you convert a decimal fraction to binary?
To convert a decimal fraction, multiply its fractional part by 2 again and again, and collect the whole-number part of each result from top to bottom. For 0.625:
- 0.625 × 2 = 1.25 → 1
- 0.25 × 2 = 0.5 → 0
- 0.5 × 2 = 1.0 → 1
So 0.625 = 0.101₂, which is ½ + ⅛. Fractions whose denominator is a power of two end cleanly, but most others repeat forever. 0.1 in binary is 0.000110011001100…, so a computer has to round it. That is why 0.1 + 0.2 gives 0.30000000000000004 in JavaScript and Python, which use 64-bit binary floating point.
The converter on this page handles whole numbers. Binary also explains storage sizes: memory is built in powers of two, which is why the GB to TB converter distinguishes TB from TiB.
When do you need decimal to binary?
You need it whenever a value has to be set bit by bit: in code, in network settings, in electronics and in computer science exams.
- Programming: setting bit flags and permissions, reading hardware registers and writing bit masks such as 0b00101000.
- Networking: working out subnet masks and which addresses share a network; 192 is 11000000, so a /26 mask ends in .192.
- Electronics: driving LEDs, shift registers and DIP switches, where each bit maps to a physical pin or switch.
- Computer science courses: exams routinely ask for the division method with the working shown.
For shorter notation, group the bits in fours and convert to hexadecimal with the decimal to hex converter. The number system converter shows octal as well.
Sources and further reading
The standards and references behind the numbers on this page. Links open in a new tab.
Standards and official sources
Decimal to binary FAQs
Short, exact answers to what people ask most.
How do you convert decimal to binary?
Divide the number by 2 and record the remainder, then keep dividing the quotient by 2 until it reaches 0. Reading the remainders from last to first gives the binary number; for 13 that is 1101.
What is 100 in binary?
100 in decimal is 1100100 in binary, because 64 + 32 + 4 = 100. It needs 7 bits.
What is 10 in binary?
10 in decimal is 1010 in binary: one 8 and one 2. In hexadecimal it is A.
What is 2026 in binary?
2,026 in decimal is 11111101010 in binary. It needs 11 bits, because it is larger than 1,024 but smaller than 2,048.
How do you write a negative number in binary?
Most computers use two's complement: write the positive value, flip every bit and add 1. In 8 bits, −5 is 11111011.
How many bits do I need to store a number?
Take the base-2 logarithm, round down and add 1. For example, 1,000 needs 10 bits and 1,000,000 needs 20 bits.
What is 5 in binary?
5 in decimal is 101 in binary: one 4 and one 1.
What is 64 in binary?
64 is 1000000 in binary, a 1 followed by six zeros, because 64 is 2 to the 6th power.
What is 500 in binary?
500 in decimal is 111110100 in binary, which needs 9 bits.
What is 127 in binary?
127 is 1111111 in binary, seven 1s. It is the largest value of a signed 8-bit integer.
What is 0.5 in binary?
0.5 is 0.1 in binary, because the first place after the binary point is worth one half.
Related conversions
Base conversion and two's complement as described in Knuth, The Art of Computer Programming, Vol. 2; binary and decimal floating point from IEEE 754-2019; DEC2BIN and BASE from the Microsoft Excel and Google Sheets documentation; bin() and format() from the Python documentation. Last updated . How we verify our numbers.