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 · ←→ step

What's happening

Pseudocode

    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-lookahead 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 only in this browser — no account needed.
    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.