Skip to content

Electronics

How to add binary numbers

To add binary numbers, work column by column from the right, exactly as in decimal, but carry as soon as a column reaches two. There are only four rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 10 (write 0, carry 1), and 1 + 1 + 1 = 11 (write 1, carry 1).

A worked example

Add 0110 (6) and 0011 (3), starting at the 1s column:

Column8s4s2s1s
Carry in110
A0110
B0011
Sum1001
  • 1s: 0 + 1 = 1, no carry
  • 2s: 1 + 1 = 10, write 0, carry 1
  • 4s: 1 + 0 + the carry = 10, write 0, carry 1
  • 8s: 0 + 0 + the carry = 1

The answer is 1001: 8 + 1 = 9, and 6 + 3 is 9. Each carry moves one place left, worth twice the column it came from.

Live experiment

Watch the carries ripple

Two 4-bit numbers, A and B, one tile per bit: tap a tile to flip it. The sum underneath is worked out column by column, and each carry hops into the next column. Make a carry ripple through three columns, then a sum too big for four bits.

Try it yourself: free lesson

“Adders” is lesson 4 of 6 in Logic Grid, Electronics World 7. Free with an account. Lessons unlock in order, so you’ll do the 45 before it first.

Overflow

Four bits hold 0 to 15. Add 1011 (11) and 0111 (7) and the true answer, 18, is 10010: five bits. A 4-bit adder has nowhere to put the top carry, so it keeps only 0010, which reads as 2. That lost carry is overflow.

Old arcade scores rolled back to zero for exactly this reason. Processors keep the lost carry in a carry flag, so a program can notice it, or chain two additions to handle numbers wider than the adder.

How hardware does it

Each column is a small circuit. The sum bit is 1 when an odd number of its inputs are 1, which is XOR. The carry is 1 when two or more are 1. A circuit for one column with a carry coming in is a full adder; chain one per bit, each carry out feeding the next carry in, and you have a ripple-carry adder. The first column has no carry in, so it can be a simpler half adder: one XOR and one AND.

Check your answer

Convert both numbers and the sum to decimal and compare. 1011 + 0101: 11 + 5 = 16, which is 10000, so in four bits it overflows to 0000. If your sum ever has a 2 in it, you forgot to carry.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“Adders” is lesson 4 of 6 in Logic Grid, Electronics World 7. Free with an account. Lessons unlock in order, so you’ll do the 45 before it first.

Or start from the very first lesson, no account needed

Work it out

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3When one column adds two 1s, it writes…
    Show the answer

    Answer: 0 and carries 1. Binary has only the digits 0 and 1, so two is written 10. The column keeps the 0 and carries the 1 to the next column, just as 9 + 1 does in decimal.

    • Why not “1 and carries 1”? 1 with a carry is 11, which is three. Two 1s make two, 10, so the column keeps 0.
    • Why not “2”? Binary has only the digits 0 and 1, so a column can't hold a 2. Two is written 10: a 0 here and a 1 carried.
  2. Question 2 of 3In the half adder, 1 + 1 gives SUM = 0 and CARRY = 1. Which gates make SUM and CARRY?
    Show the answer

    Answer: SUM is XOR, CARRY is AND. The sum bit is 1 for 0 + 1 and 1 + 0, and 0 for 0 + 0 and 1 + 1: exactly XOR's table. The carry is 1 only for 1 + 1: exactly AND's.

    • Why not “SUM is OR, CARRY is AND”? OR gives 1 for 1 + 1, but the sum bit there is 0. Only XOR's table matches the sum column.
    • Why not “SUM is AND, CARRY is XOR”? That's backwards: AND is 1 only for 1 + 1, which is the carry, and XOR is 1 for 0 + 1 and 1 + 0, which is the sum.
    • Why not “Both are XOR”? An XOR carry would be 1 for 0 + 1, which never carries. The carry is 1 only for 1 + 1, which is AND's table.
  3. Question 3 of 3The 1s and 2s wires are on, the 4s and 8s off. The number is…
    Show the answer

    Answer: 3. 1 + 2 = 3.

    • Why not “1”? 1 counts only the 1s wire. The 2s wire is on too, adding 2 more.
    • Why not “6”? 6 would be the 4s and 2s wires. With the 1s and 2s on, the value is 1 + 2.
    • Why not “12”? 12 is the 8s and 4s together, the two wires that are off here.
Keep practising: free lesson

“Adders” is lesson 4 of 6 in Logic Grid, Electronics World 7. Free with an account. Lessons unlock in order, so you’ll do the 45 before it first.

Questions people ask

What is 1 + 1 in binary?

10, which is two. Binary has only the digits 0 and 1, so a column holding two writes 0 and carries 1 into the next column, just as 9 + 1 in decimal writes 0 and carries 1.

What is overflow in binary addition?

A sum too big for the number of bits. Four bits hold 0 to 15, so 9 + 8 = 17 needs a fifth bit; the carry out of the top column is lost and only 0001 remains. Processors keep that lost carry in a carry flag.

How do computers subtract in binary?

They add the two's complement: flip every bit of the number being taken away, add 1, then add as usual and drop the carry out of the top. 7 − 2 becomes 0111 + 1110 = 1 0101, and the four bits left, 0101, are 5.

Every topic