1. Home
  2. Computer Organization & Architecture
  3. Ripple-Carry Adder

Ripple-Carry Adder

Add two binary numbers with a chain of full adders and watch the carry ripple from the lowest bit to the highest.

Interactive 3DBeginner10 min readCOAUpdated

Drag to rotate · Right-drag to pan · Click, then scroll to zoom · Space play · Left arrowRight arrow step

What's happening

A ripple-carry adder chains one full adder per bit; the carry “ripples” from the least significant bit upward. Enter two numbers from 0 to 15 and press Add.

Pseudocode

  1. carry ← 0
  2. for i ← 0 to 3: // least significant bit first
  3. sum[i] ← A[i] XOR B[i] XOR carry
  4. carry ← (A[i] AND B[i]) OR (carry AND (A[i] XOR B[i]))
  5. sum[4] ← carry // final carry-out
Read this model as text · 7 steps

One run of the model above, written out step by step. Useful with a screen reader, on a slow connection, or for quick revision. The values may differ from the run on your screen.

  1. A ripple-carry adder chains one full adder per bit; the carry “ripples” from the least significant bit upward. Enter two numbers from 0 to 15 and press Add.
  2. Add A = 11 (1011) and B = 6 (0110). Each bit has its own full adder (FA). The carry-in of bit 0 is 0.
  3. Bit 0: 1 + 0 + carry 0 = 1. Sum bit = 1 (XOR of the three inputs), carry-out = 0 (at least two inputs are 1).
  4. Bit 1: 1 + 1 + carry 0 = 2. Sum bit = 0 (XOR of the three inputs), carry-out = 1 (at least two inputs are 1).
  5. Bit 2: 0 + 1 + carry 1 = 2. Sum bit = 0 (XOR of the three inputs), carry-out = 1 (at least two inputs are 1).
  6. Bit 3: 1 + 0 + carry 1 = 2. Sum bit = 0 (XOR of the three inputs), carry-out = 1 (at least two inputs are 1).
  7. The last carry becomes bit 4 of the result: 10001 = 17. A carry-out of 1 from the top bit means an unsigned overflow in a 4-bit register. Each carry must wait for the one before it, so the delay grows with the number of bits: O(n).

Try this in the 3D model

  • Add 11 + 6. At which bit does a carry first appear?
  • Press Overflow example: 15 + 1. Follow the carry through all four adders.
  • Add 5 + 2. Why do no carries happen here?
  • Find two numbers whose sum needs a carry out of the top bit but is less than 16 in your head. Is it possible?

Adding like in primary school

When you add 47 + 38 on paper you add the rightmost column, write the digit, carry the extra and move left. A binary adder does exactly this, one full adder per column.

The full adder

A full adder takes three bits, A, B and carry-in, and produces two:

sum       = A XOR B XOR carry-in
carry-out = (A AND B) OR (carry-in AND (A XOR B))
A B Cin Sum Cout
0 0 0 0 0
0 1 0 1 0
1 1 0 0 1
0 1 1 0 1
1 1 1 1 1

Chaining them

Connect the carry-out of each adder to the carry-in of the next. The first carry-in is 0. The carry ripples upward, which gives the circuit its name.

Example: 11 + 6 = 1011 + 0110

Bit A B Carry in Sum Carry out
0 1 0 0 1 0
1 1 1 0 0 1
2 0 1 1 0 1
3 1 0 1 0 1

The final carry becomes bit 4, giving 10001 = 17.

Speed

Bit 3 cannot produce its sum until bit 2’s carry is ready, which waits for bit 1, and so on. The delay is O(n). Real CPUs use carry look-ahead adders that work out all carries at once from “generate” (A AND B) and “propagate” (A XOR B) signals, so 64-bit addition still takes only a few gate delays.

Overflow

With unsigned numbers, a carry out of the top bit means the result does not fit. With two’s complement numbers, overflow happens when two numbers of the same sign give a result of the opposite sign.

Code

def ripple_add(a, b, n=4):
    carry, total = 0, 0
    for i in range(n):
        x, y = (a >> i) & 1, (b >> i) & 1
        total |= (x ^ y ^ carry) << i
        carry = (x & y) | (carry & (x ^ y))
    return total | (carry << n)

print(ripple_add(11, 6))   # 17

Common mistakes

  • Forgetting the carry-in when filling the truth table: a full adder has three inputs, not two.
  • Reading the sum from left to right. Bit 0 is the rightmost bit.
  • Dropping the final carry. In an unsigned add it is the fifth bit of the answer.

Complexity at a glance

Case / operationTimeWhy
Add two n-bit numbersO(n)Each carry waits for the previous adder, so the delay is n full-adder delays.
Carry-lookahead adderO(log n)Computes all carries in parallel using generate and propagate signals.
Extra spacen full adders (about 5 gates each)

Quick check

Test yourself — pick an answer to see if you got it.

1. What are the inputs of a full adder?

2. What is the sum bit of a full adder with inputs 1, 1 and carry-in 1?

3. Why is a ripple-carry adder slow for wide numbers?

4. A 4-bit unsigned adder produces a carry-out of 1 from the top bit. What does it mean?

Saved in this browser.
Spotted a mistake or a bug in the 3D model?

Report a mistake

in Ripple-Carry Adder. Thank you — every report makes the lesson better for the next reader.

We'll also include a link to the step of the 3D model you're on and your browser type, so we can reproduce it.