Math

Binary Calculator

Perform binary arithmetic operations: add, subtract, multiply, and divide binary numbers. See results in both binary and decimal.

Result (Binary)
10000
1010 + 0110 = 10000
Result (Decimal)
16
1010 in decimal
10
0110 in decimal
6

What is binary?

Binary is a base-2 numeral system that uses only two digits: 0 and 1. Unlike the decimal system (base-10) that we use in everyday life, which has ten digits (0-9), binary represents all numbers using combinations of just these two symbols. This simplicity makes binary the foundation of all modern digital computing.

Each digit in a binary number is called a bit (short for "binary digit"). When bits are grouped together, they form larger units: 8 bits make a byte, which can represent values from 0 to 255. Computers use binary because electronic circuits can easily distinguish between two states: on (1) and off (0), high voltage and low voltage, or magnetized and demagnetized.

How binary numbers work

In binary, each position represents a power of 2, starting from the rightmost position (2⁰ = 1). Moving left, each position doubles in value: 2¹ = 2, 2² = 4, 2³ = 8, and so on.

Position76543210
Power of 22⁷2⁶2⁵2⁴2⁰
Decimal value1286432168421

To convert a binary number to decimal, multiply each bit by its position value and sum the results. For example, the binary number 1010:

10102=(1×23)+(0×22)+(1×21)+(0×20)=8+0+2+0=1010\begin{aligned} 1010_2 &= (1 \times 2^3) + (0 \times 2^2) + (1 \times 2^1) + (0 \times 2^0) \\ &= 8 + 0 + 2 + 0 \\ &= 10_{10} \end{aligned}

Binary addition

Binary addition follows similar rules to decimal addition but with only two digits. The basic addition rules are:

ABSumCarry
0000
0110
1010
1101

The key difference from decimal addition is that 1 + 1 = 10 in binary (which equals 2 in decimal). This generates a carry of 1 to the next position.

Example: Adding 1010 and 0110

    1010  (10 in decimal)
  + 0110  (6 in decimal)
  ------
   10000  (16 in decimal)

Working from right to left:

  • Column 0: 0 + 0 = 0
  • Column 1: 1 + 1 = 0, carry 1
  • Column 2: 0 + 1 + 1 (carry) = 0, carry 1
  • Column 3: 1 + 0 + 1 (carry) = 0, carry 1
  • Column 4: 0 + 0 + 1 (carry) = 1

Binary subtraction

Binary subtraction uses borrowing, similar to decimal subtraction. The basic rules are:

ABDifferenceBorrow
0000
1010
1100
0111

When subtracting 1 from 0, you need to borrow from the next higher position. Borrowing 1 from the next position gives you 2 (in decimal terms), so 10 - 1 = 1 in binary.

Example: Subtracting 0110 from 1010

    1010  (10 in decimal)
  - 0110  (6 in decimal)
  ------
    0100  (4 in decimal)

Working from right to left:

  • Column 0: 0 - 0 = 0
  • Column 1: 1 - 1 = 0
  • Column 2: 0 - 1 requires borrowing; becomes 10 - 1 = 1
  • Column 3: 0 - 0 = 0 (after lending 1 to column 2)

Binary multiplication

Binary multiplication is simpler than decimal multiplication because you only multiply by 0 or 1. The rules are straightforward:

ABProduct
000
010
100
111

Binary multiplication uses the same long multiplication method as decimal, but each partial product is either 0 (when multiplying by 0) or a shifted copy of the multiplicand (when multiplying by 1).

Example: Multiplying 1010 by 0110

      1010  (10 in decimal)
    × 0110  (6 in decimal)
    ------
      0000  (1010 × 0)
     1010   (1010 × 1, shifted left 1)
    1010    (1010 × 1, shifted left 2)
   0000     (1010 × 0, shifted left 3)
  --------
   111100   (60 in decimal)

Binary division

Binary division follows the long division algorithm. You repeatedly determine whether the divisor fits into the current portion of the dividend, subtract if it does, and bring down the next bit.

Example: Dividing 1010 by 0010

        101   (quotient: 5 in decimal)
      -----
0010 | 1010   (dividend: 10 in decimal)
       -10    (subtract 0010 × 1)
       ---
        01
        -0    (0010 doesn't fit)
        --
        10
       -10    (subtract 0010 × 1)
       ---
         0    (remainder)

Result: 1010 ÷ 0010 = 101 (10 ÷ 2 = 5 in decimal)

When division doesn't result in a whole number, the calculator shows the integer quotient (floor division) and the remainder.

Two's complement for negative numbers

Computers typically use two's complement representation for negative numbers. In this system, the leftmost bit indicates the sign (0 for positive, 1 for negative), and negative numbers are represented by inverting all bits and adding 1.

For example, to represent -5 in an 8-bit system:

  1. Start with 5: 00000101
  2. Invert all bits: 11111010
  3. Add 1: 11111011

This calculator performs standard unsigned binary arithmetic. For negative results in subtraction, it displays the negative sign separately rather than using two's complement notation.

Applications of binary arithmetic

Computer processors

Every calculation your computer performs ultimately happens in binary. When you add two numbers in a spreadsheet or calculate distances in a video game, the processor converts these operations to binary arithmetic.

Digital circuits

Logic gates—the building blocks of all digital electronics—implement binary operations directly. An AND gate outputs 1 only when both inputs are 1 (binary multiplication), while an XOR gate outputs 1 when inputs differ (binary addition without carry).

Networking

IP addresses, subnet masks, and network calculations all use binary arithmetic. Network engineers regularly convert between binary and decimal to understand routing and subnetting.

Data storage

File sizes, memory addresses, and storage calculations use binary. This is why storage devices show sizes in powers of 2 (512 GB, 1024 MB, etc.) and why 1 KB equals 1024 bytes, not 1000.

Cryptography

Many encryption algorithms rely on binary operations like XOR for combining keys with plaintext. Understanding binary arithmetic is essential for studying how encryption works.

Common binary conversions

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

Tips for working with binary

Recognizing powers of 2

Numbers that are powers of 2 have only one bit set to 1 in binary:

  • 1 = 1
  • 2 = 10
  • 4 = 100
  • 8 = 1000
  • 16 = 10000

Quick mental conversion

For small binary numbers, count the positions where 1 appears and add the corresponding powers of 2. For 1101: positions 0, 2, and 3 are set, so 1 + 4 + 8 = 13.

Checking your work

The decimal result of any binary operation should make sense. If adding two small binary numbers gives an unexpectedly large decimal result, double-check your binary-to-decimal conversion.

Limitations of this calculator

This calculator performs integer arithmetic only. Division results are truncated to whole numbers (floor division). For fractional binary representations or floating-point binary, specialized tools are needed.

The calculator accepts binary numbers of reasonable length. Very large binary numbers may exceed the precision limits of JavaScript's number representation (safe integers up to 2⁵³ - 1).

Negative results from subtraction are displayed with a minus sign prefix rather than in two's complement format.