Convert Decimal to Binary

Convert decimal numbers to binary using the division-by-2 method. Step-by-step guide with worked examples and tips for quick mental conversions online.

Decimal (Base 10)Binary (Base 2)Conversion

Detailed Explanation

Converting decimal to binary is the reverse of binary-to-decimal and is equally important for anyone working with computers. The most common technique is the repeated division by 2 method.

Step-by-step example — converting 42 to binary:

  1. Divide 42 by 2: quotient = 21, remainder = 0
  2. Divide 21 by 2: quotient = 10, remainder = 1
  3. Divide 10 by 2: quotient = 5, remainder = 0
  4. Divide 5 by 2: quotient = 2, remainder = 1
  5. Divide 2 by 2: quotient = 1, remainder = 0
  6. Divide 1 by 2: quotient = 0, remainder = 1

Read the remainders from bottom to top: 101010. So 42₁₀ = 101010₂.

Alternative method — subtraction of powers of 2:

Start with the largest power of 2 that fits into your number and subtract downward:

  • 42 - 32(2⁵) = 10, write 1
  • 10 - 16(2⁴)? No. Write 0
  • 10 - 8(2³) = 2, write 1
  • 2 - 4(2²)? No. Write 0
  • 2 - 2(2¹) = 0, write 1
  • 0 - 1(2⁰)? No. Write 0

Result: 101010₂. This subtraction method is often faster for mental arithmetic.

Practical tips:

  • Round numbers like 64, 128, and 256 convert instantly because they are exact powers of 2.
  • To convert a number like 255, recognize it is 2⁸ - 1, so the binary representation is eight 1s: 11111111.
  • In programming, you can verify your result using parseInt("101010", 2) in JavaScript or int("101010", 2) in Python, both of which return 42.

Understanding decimal-to-binary conversion is critical for implementing hash functions, encoding data, and working with binary protocols.

Use Case

Network engineers convert decimal subnet mask values like 255, 252, or 248 into binary to understand exactly which bits define the network versus host portions of an IP address.

Try It — Number Base Converter

Open full tool