Skip to content

Decimal to Binary Converter

Convert a decimal number to binary. Try 13 to get 1101 and see how each bit follows from the remainders.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is Decimal to Binary Converter?

This decimal to binary converter turns ordinary base-10 numbers, also called denary, into base 2, the ones and zeros computers work with. 5 is 101, 45 is 101101 and 255 is 11111111. Seeing a number in binary shows exactly which bits are set, which matters for bit flags, masks, permissions and low-level code.

Enter one number or several separated by spaces or commas, and each is converted instantly. Values are padded to 8 bits by default so bytes line up neatly; turn padding off to see the shortest form.

How to use Decimal to Binary Converter

  1. Enter decimal numbers separated by spaces or commas, for example 5 45
  2. Read the binary results, padded to whole 8-bit bytes.
  3. Turn padding off or change the separator if you prefer.
  4. Copy the result, or click Swap to convert binary to decimal.

Key features

  • Convert many values at once, separated by spaces or commas
  • Exact results for numbers of any size, including 64-bit values
  • Output separated by spaces, commas, new lines or nothing
  • Uppercase or lowercase hex, optional 0x prefix, and binary padded to whole 8-bit bytes
  • Swap button to reverse the conversion direction
  • Summary of a single value in binary, octal, decimal, hex and ASCII
  • Clear errors for invalid digits; runs entirely in your browser

Common use cases

  • Working out which bits are set in flags and masks
  • Learning binary for computer science classes and exams
  • Converting subnet mask octets such as 255.255.240.0 to bits
  • Preparing binary values for embedded and hardware work
  • Checking homework answers

Technical details & standards

To convert by hand, divide by 2 repeatedly and write down the remainders, then read them from last to first. For 45: 45 ÷ 2 = 22 r1, 22 ÷ 2 = 11 r0, 11 ÷ 2 = 5 r1, 5 ÷ 2 = 2 r1, 2 ÷ 2 = 1 r0, 1 ÷ 2 = 0 r1, giving 101101. Alternatively subtract the largest powers of two: 45 = 32 + 8 + 4 + 1.

Each value is converted as a whole number. With byte padding on, results are padded to a multiple of 8 bits, so 256 becomes 0000000100000000; turn padding off to get 100000000. Values of any size are exact, because the arithmetic uses arbitrary-precision integers. Negative numbers are shown with a minus sign rather than in two's complement; the Programmer Calculator shows bitwise forms.

Decimal to binary without dividing: subtract powers of two

Repeated division by 2 always works, but for numbers under 256 it is often faster to subtract the largest power of two that fits. Here is 205, using the place values 128, 64, 32, 16, 8, 4, 2 and 1:

  1. 128 fits into 205, so write 1 and keep 205 − 128 = 77.
  2. 64 fits into 77, so write 1 and keep 13.
  3. 32 and 16 do not fit into 13, so write 0 and 0.
  4. 8 fits into 13, so write 1 and keep 5.
  5. 4 fits into 5, so write 1 and keep 1. 2 does not fit, so write 0. 1 fits, so write 1 and keep 0.

Result: Reading the digits in order gives 205 = 11001101. The converter above shows the division-by-2 method for any number you enter, so you can compare both.

Dec to binary in JavaScript, Python and Excel

Dec to bin (sometimes written dectobin or int to bit) is a one-liner in most languages. Pad the result when you need whole bytes.

JavaScript

(10).toString(2);                 // "1010"
(45).toString(2).padStart(8, "0"); // "00101101"
(1022).toString(2);               // "1111111110"

Python

bin(10)           # '0b1010'
format(10, "b")   # '1010', without the 0b prefix
format(45, "08b") # '00101101'
f"{1022:b}"       # '1111111110'

Excel

=DEC2BIN(45)      → 101101
=DEC2BIN(45, 8)   → 00101101

DEC2BIN accepts −512 to 511 only. For larger numbers up to 262,143, split at 512: =DEC2BIN(INT(A1/512))&DEC2BIN(MOD(A1,512),9) turns 1022 into 1111111110.

Decimal to binary conversion table

Decimal 0 to 15 fit in four bits, as the first table shows. The second lists decimal numbers whose binary form comes up in class and in code, padded to whole bytes the way the converter shows them by default.

Decimal 0–15 in binary and hex

DecimalBinaryHex
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F

Common decimal values in binary

DecimalBinaryWhere you see it
20000 0010The base itself, so it is written 10
100000 1010Ten is 8 + 2, so bits 3 and 1 are set
160001 0000The first number that needs five bits
300001 111016 + 8 + 4 + 2, four 1s then a 0
320010 0000ASCII space
450010 110132 + 8 + 4 + 1
640100 00002⁶, a single 1 followed by six zeros
1000110 0100A round decimal number with an untidy binary form
1180111 011064 + 32 + 16 + 4 + 2
1270111 1111Largest signed 8-bit value
1281000 0000Only the top bit of a byte set
2051100 1101Worked by subtracting powers of two, above
2551111 1111Largest value one byte can hold
2560001 0000 0000One more than a byte can hold, so it needs 9 bits
1,0000011 1110 1000Milliseconds in a second
1,0220011 1111 1110Two less than 1024: nine 1s and a 0
1,0240100 0000 00001 KiB, 2¹⁰
65,5351111 1111 1111 1111Largest unsigned 16-bit value

Frequently asked questions

How do I convert decimal to binary?

Divide by 2 repeatedly and read the remainders from bottom to top. For 13: remainders 1, 0, 1, 1 read in reverse give 1101.

What is 255 in binary?

11111111, eight ones. It is the largest number that fits in one byte.

What is 10 in binary?

1010: 8 + 2. With 8-bit padding it is written 00001010.

How do I convert decimal to binary in code?

JavaScript: (45).toString(2) returns "101101". Python: bin(45) returns '0b101101', or format(45, "08b") for an 8-bit string.

What is the formula for decimal to binary conversion?

Repeated division by 2: divide the number by 2, write down the remainder (0 or 1), divide the quotient by 2 again, and stop at 0. The remainders read from last to first are the binary digits. For 13: 6 r1, 3 r0, 1 r1, 0 r1, giving 1101.

How do I convert the denary value 164 to binary?

164 is 10100100 in binary: 128 + 32 + 4 = 164.

What is 0.1 in binary?

0.1 is 0.000110011… in binary, and the pattern repeats forever. That is why 0.1 cannot be stored exactly as a floating-point number. This converter works with whole numbers.

What is 14 (written 14₁₀) in binary: 101, 1101, 1110 or 10000?

1110₂. Fourteen is 8 + 4 + 2, so the 8, 4 and 2 places hold a 1 and the 1s place holds a 0. 1101₂ is 13 and 10000₂ is 16, which makes them the usual wrong answers in this quiz question.

What are the numbers 1 to 20 in binary?

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 and 20 = 10100. Each time the number reaches a power of two (2, 4, 8, 16) it gains one more bit.

What are 100 and 1000 in binary?

100 is 1100100 (64 + 32 + 4) and 1000 is 1111101000 (512 + 256 + 128 + 64 + 32 + 8). With byte padding on, 100 is shown as 01100100 and 1000 as 0000001111101000.

What is 45 in binary?

101101, or 00101101 as a full byte. 45 is 32 + 8 + 4 + 1, so those four places are 1 and the 16 and 2 places are 0.

More converters tools

View all