About the Decimal to Binary
Convert decimal to binary instantly: type an ordinary base-10 number and get its base-2 form in 0s and 1s. You might want it for a computer science class, for bit flags and masks in code or for subnetting practice, or just to see how a computer stores a number such as 45 or 1,000,000.
Numbers far larger than a typical calculator can hold still convert exactly. 9007199254740993, the first whole number a JavaScript double can't store, converts to a 54-digit binary string that ends in 1, exactly as it should.
How it works
The classic method is repeated division by 2. Divide the number by 2, write down the remainder (always 0 or 1), and carry on dividing the quotient until it reaches 0. The remainders read from the last one to the first are the binary digits.
The converter does exactly that with arbitrary-precision integers (BigInt), so a 20-digit decimal input is handled with the same accuracy as 45. The answer is written without leading zeros: 5 comes out as 101, not 00000101.
repeat while n > 0: bit = n mod 2 n = floor(n ÷ 2) binary = the bits in reverse order (last remainder first)
A quicker way for small numbers is to subtract the largest power of two that fits (128, 64, 32 …), write a 1 for each power you used and a 0 for each you skipped.
Assumptions and limits
- Only whole numbers are converted. Decimal fractions such as 2.5 and scientific notation such as 1e3 are refused with a message; type 1000 in full instead.
- Negative numbers come out with a minus sign, so −6 gives −110. This is not the two's complement bit pattern a processor would store (11111010 in 8 bits).
- Commas are accepted only as thousands separators (1,000,000). A single space or underscore may also split the digits, as in 1 000 000 or 1_000_000.
- The output has no leading zeros and no 0b prefix. Pad it on the left yourself if you need a fixed width such as 8, 16 or 32 bits.
- Inputs can be up to 4,096 decimal digits long, which still covers numbers with more than 13,000 bits.
Worked examples
Decimal 156 to binary by repeated division
Eight divisions bring 156 down to 0. Reading the remainders from bottom to top gives 10011100, which you can check as 128 + 16 + 8 + 4 = 156.
156 ÷ 2 = 78 r 0 78 ÷ 2 = 39 r 0 39 ÷ 2 = 19 r 1 19 ÷ 2 = 9 r 1 9 ÷ 2 = 4 r 1 4 ÷ 2 = 2 r 0 2 ÷ 2 = 1 r 0 1 ÷ 2 = 0 r 1 → 10011100
One million in binary
Typing 1,000,000 with commas works and returns 11110100001001000000, a 20-bit number. That is why a counter that must reach a million needs at least 20 bits of storage.
Building a permission bit mask
If read, write and execute flags are worth 4, 2 and 1, a value of 6 converts to 110: read and write on, execute off. Converting 5 gives 101, read and execute on.
Decimal to binary conversion table
Common values, from small counts to the 16-bit maximum. Read right to left to go from binary back to decimal.
| Decimal | Binary | Bits needed |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 10 | 2 |
| 3 | 11 | 2 |
| 5 | 101 | 3 |
| 8 | 1000 | 4 |
| 12 | 1100 | 4 |
| 20 | 10100 | 5 |
| 25 | 11001 | 5 |
| 50 | 110010 | 6 |
| 99 | 1100011 | 7 |
| 100 | 1100100 | 7 |
| 128 | 10000000 | 8 |
| 200 | 11001000 | 8 |
| 255 | 11111111 | 8 |
| 500 | 111110100 | 9 |
| 1000 | 1111101000 | 10 |
| 2048 | 100000000000 | 12 |
| 65535 | 1111111111111111 | 16 |
How to use the Decimal to Binary
- Type a decimal number. Overwrite the sample 45 with any whole number; thousands commas like 1,000,000 are fine.
- Check the binary output. The base-2 digits appear on the right as you type, with an explanation if the input isn't a whole number.
- Copy it. Press Copy Result and paste the bits where you need them, adding leading zeros for a fixed width.
Frequently asked questions
What is 10 in binary?
1010. Ten is 8 + 2, so the 8s place and the 2s place get a 1 and the 4s and 1s places get a 0. Likewise 100 is 1100100 and 1,000 is 1111101000.
How do I get an 8-bit or 16-bit result with leading zeros?
Add the zeros yourself. The converter shows the shortest form, so 5 appears as 101; put zeros on the left until you reach the width you need: 00000101 for 8 bits, 0000000000000101 for 16. The value is unchanged.
How do you write a negative decimal number in binary?
This page keeps the sign, so −6 becomes −110. Computers usually store negatives in two's complement instead: flip every bit of 6 in your chosen width (00000110 → 11111001) and add 1, giving 11111010 for −6 in 8 bits.
Can I convert a decimal with a fractional part, like 0.75?
Not here; fractions are refused so you never get a silently truncated answer. By hand, multiply the fraction by 2 repeatedly and note the whole parts: 0.75 → 1.5 (1), 0.5 → 1.0 (1), so 0.75 is 0.11 in binary.
Why do some calculators give a wrong binary answer for very large numbers?
A tool that stores the input as a 64-bit floating-point number can only hold whole numbers exactly up to 9,007,199,254,740,991. Above that the last digits are rounded before the conversion even starts. This tool uses exact big-integer arithmetic, so 9007199254740993 converts correctly.
Does the conversion happen on my device?
Yes. The repeated division runs in your browser as you type and nothing is sent anywhere, so it also works offline once the page has loaded.
This tool runs entirely in your browser. What you enter or upload stays on your device and is never sent to our servers.