AlgoPlusAlgoPlus
Learn/Computer Architecture
Lesson

Binary Addition

Adding column by column in hardware with a chain of full adders — the ripple-carry adder and why it is O(n).

8 min read Watch it move Build it

Binary addition works exactly like the decimal addition you learned in school, except each column holds only 0 or 1 and a column overflows as soon as its total reaches 2. When that happens it writes a sum digit and passes a carry to the next column on the left.

One column = one full adder

Each column adds three bits: a bit from A, a bit from B, and the carry-in from the column to its right. A full adder produces two outputs: Sum = A XOR B XOR Cin (the digit written down) and Carry = (A AND B) OR (Cin AND (A XOR B)) (handed to the next column). The carry-out is 1 whenever at least two of the three inputs are 1.

Chaining them — the ripple-carry adder

A ripple-carry adder wires n full adders in a row, feeding each column's carry-out into the next column's carry-in, starting from the rightmost (least-significant) bit with carry-in 0. It is the simplest possible adder to build.

Add 0110 (6) + 0101 (5), right to left:

  carry:  0 1 0 0
     A :  0 1 1 0
     B :  0 1 0 1
  ----------------
   sum :  1 0 1 1   = 11

  col0: 0+1+0 = 1, carry 0
  col1: 1+0+0 = 1, carry 0
  col2: 1+1+0 = 0, carry 1   <- spills over
  col3: 0+0+1 = 1, carry 0
The carry has to ripple
Column 3's correct answer depends on column 2's carry, which depends on column 1's, and so on. The columns cannot finish in parallel — each waits on the one before it. For an n-bit adder the carry takes about n gate delays to settle, so the adder is O(n) in time.
Carry-lookahead breaks the chain
A carry-lookahead adder computes every carry *directly from the inputs* using "generate" (A AND B) and "propagate" (A XOR B) signals, instead of waiting for the ripple. It costs far more gates but cuts the delay from O(n) toward O(log n) — the standard speedup in real CPUs.
OperationTimeSpace
Ripple-carry adder · carry chains column to columnO(n) gate delaysn full adders
Carry-lookahead adder · carries computed in parallel~O(log n) delaysmore logic
Check yourself
Why is an n-bit ripple-carry adder O(n) in gate delay rather than O(1)?