Function · Math

Excel DEC2BIN function

The Excel DEC2BIN function converts a decimal number to binary text. DEC2BIN(9) is 1001, DEC2BIN(9,8) is 00001001, and DEC2BIN(-1) is 1111111111.

Excel 365, Excel 2024, Excel 2021, Excel 2019, and earlier. Also in Excel for the web and Google Sheets.

Syntax =DEC2BIN(number, [places])

DEC2BIN
=DEC2BIN(9,8)

Arguments

NameRequiredWhat to pass
numberRequiredThe whole number to convert, from -512 through 511. A fraction is cut down, so 9.9 converts as 9. A negative number returns a 10-character two's complement. Outside that range is #NUM!. Text that is not a number, such as nine, is #VALUE!.
placesOptionalHow many characters to return, padded with leading zeros. DEC2BIN(9,8) is 00001001. A fraction is cut down. Too few places for the result, or a places of 0 or less, is #NUM!. Microsoft documents that places is ignored for a negative number and that text in places is #VALUE!.

Examples

Decimal to binary

=DEC2BIN(9)

Result 1001

Pad to 8 bits with places

=DEC2BIN(192,8)&"."&DEC2BIN(168,8)&"."&DEC2BIN(1,8)&"."&DEC2BIN(10,8)

Result 11000000.10101000.00000001.00001010

Negative numbers are 10-bit two's complement

=DEC2BIN(-100)

Result 1110011100

Past 511, use BASE

=BASE(1000,2)

Result 1111101000

=DEC2BIN(B2,8)C2
Network
ABC
1PartDecimalBinary
2119211000000
3216810101000
43100000001
541000001010
A picture of the sheet, not a live calculator. Column B holds the four parts of 192.168.1.10, and column C pads each one to 8 bits.

DEC2BIN converts a decimal number to binary and returns it as text. =DEC2BIN(9) is 1001, =DEC2BIN(255) is 11111111, and =DEC2BIN(0) is 0. It is one of Excel’s engineering conversions, next to DEC2HEX and DEC2OCT. =DEC2HEX(255) is FF and =DEC2OCT(255) is 377. A fraction is cut down before the conversion, so =DEC2BIN(9.9) is 1001.

The optional places argument pads the result with leading zeros. =DEC2BIN(9,8) is 00001001, a full byte. An IPv4 address is four bytes, so 192.168.1.10 in binary is =DEC2BIN(192,8)&"."&DEC2BIN(168,8)&"."&DEC2BIN(1,8)&"."&DEC2BIN(10,8), 11000000.10101000.00000001.00001010. Places has to be big enough for the answer. =DEC2BIN(9,3) is #NUM!, because 1001 needs four characters. This padding is the same idea as the xl.pad.zip LAMBDA, which puts back the leading zero a ZIP code loses, except DEC2BIN does it for you.

The result is text. =ISTEXT(DEC2BIN(5)) is TRUE. If you add 0 to it, =DEC2BIN(5)+0 is the number 101, which reads as one hundred one, not five. To count the 1 bits, strip the zeros with SUBSTITUTE and measure what is left with LEN. =LEN(SUBSTITUTE(DEC2BIN(168),"0","")) is 3. TEXT and REPT are not needed for padding, because places already does it.

Negative numbers come back as a 10-bit two’s complement, always 10 characters, and the first bit is the sign. =DEC2BIN(-1) is 1111111111, =DEC2BIN(-2) is 1111111110, =DEC2BIN(-100) is 1110011100, and =DEC2BIN(-512) is 1000000000. Microsoft documents that places is ignored for a negative number. BIN2DEC reads the sign bit the same way, so =BIN2DEC("1110011100") is -100 and =BIN2DEC("1111111111") is -1. That is why DEC2BIN stops at -512 and 511. Ten bits hold 1,024 values, half of them negative.

Anything outside -512 through 511 is #NUM!. =DEC2BIN(512) and =DEC2BIN(1000) both fail. BASE, in Excel 2013 and later, converts larger numbers. =BASE(1000,2) is 1111101000, and =BASE(1000000,2) is 11110100001001000000, 20 characters. Its third argument pads like places, so =BASE(1000,2,16) is 0000001111101000. BASE takes 0 up to, but not including, 2^53, and Microsoft documents #NUM! past that. It does not take negative numbers, and =BASE(-1,2) is #NUM!. For a 10-bit negative, add 1,024 first. =BASE(1024-100,2) is 1110011100, the same as =DEC2BIN(-100).

BIN2DEC is the reverse of DEC2BIN. =BIN2DEC("1001") is 9, and =BIN2DEC(DEC2BIN(255)) is 255. BIN2DEC takes up to 10 binary digits, so =BIN2DEC("11111111111"), with 11, is #NUM!. DECIMAL is the reverse of BASE and has no 10-digit limit. =DECIMAL("1111101000",2) is 1000.

Text that is not a number is #VALUE!, so =DEC2BIN("nine") and =DEC2BIN("") fail. Text that looks like a number converts, and =DEC2BIN("9") is 1001. DEC2BIN works in Excel 365, Excel 2024, 2021, 2019, and older desktop versions, as well as Excel for the web and Google Sheets. In Excel 2003 it came with the Analysis ToolPak. BASE and DECIMAL need Excel 2013 or later. CONVERT changes measurement units rather than number bases, ROMAN writes Roman numerals, and MOD returns the remainder that the divide-by-2 method of converting by hand uses.

None of the xlambda.io workbooks needs binary. DEC2BIN fits network, permission-flag, and engineering sheets that you build yourself.