Binary Adder: Half Adder, Full Adder & Ripple-Carry
Toggle the inputs of a half adder or full adder and watch the XOR, AND and OR gates, then chain full adders into a 4, 8, 16 or 32-bit ripple-carry adder.
Half adder
1 + 1 = 10 in binary (2 in decimal)
Full adder
1 + 0 + 1 = 10 in binary (2 in decimal)
Ripple-carry adder
Chain one full adder per bit: each stage's carry-out becomes the next stage's carry-in. Enter two binary numbers and follow the carry from bit 0 upward.
carry 0111
A 0101
B + 0011
────
01000| Stage (bit) | A | B | Cin | A ⊕ B | Sum | Cout |
|---|---|---|---|---|---|---|
| 0 (LSB) | 1 | 1 | 0 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 | 1 | 0 | 1 |
| 2 | 1 | 0 | 1 | 1 | 0 | 1 |
| 3 (MSB) | 0 | 0 | 1 | 0 | 1 | 0 |
Longest carry chain this time: 3 stages of 4. In the worst case (all ones plus one) the carry has to ripple through every stage, which is why fast CPUs use carry-lookahead adders instead.
Half adder truth table
| A | B | Sum | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
Sum = A XOR B, Carry = A AND B.
Full adder truth table
| A | B | Cin | Sum | Cout |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
Sum = A XOR B XOR Cin, Cout = (A AND B) OR (Cin AND (A XOR B)). The sum is 1 when an odd number of inputs are 1; the carry is 1 when at least two are.
Subtraction with the same adder
Feed the adder ~B instead of B and set the carry-in to 1, and it computes A + (~B + 1) = A − B in two's complement. That is how one ALU adds and subtracts - the binary subtraction calculator shows the borrow and overflow flags it produces. For plain arithmetic on binary numbers use the binary calculator, and for AND, OR and XOR across whole words the bitwise calculator.
Code Examples
def full_adder(a, b, cin):
s = a ^ b ^ cin
cout = (a & b) | (cin & (a ^ b))
return s, cout
def ripple_add(a, b, width=8):
carry, total = 0, 0
for i in range(width):
s, carry = full_adder((a >> i) & 1, (b >> i) & 1, carry)
total |= s << i
return total, carryFrequently Asked Questions
What is a half adder?
A circuit that adds two bits. Its sum output is A XOR B and its carry output is A AND B, so 1 + 1 gives sum 0, carry 1 (binary 10). It is "half" because it has no carry input, so it cannot take a carry from a lower bit.
What is a full adder?
A circuit that adds three bits: A, B and a carry-in. Sum = A XOR B XOR Cin, and Carry-out = (A AND B) OR (Cin AND (A XOR B)). It is built from two half adders and an OR gate, and it is the building block of every multi-bit adder.
How does a ripple-carry adder work?
It chains one full adder per bit. Each stage's carry-out feeds the next stage's carry-in, so a carry can "ripple" from the lowest bit to the highest. That chain is also its weakness: the top bit cannot settle until every carry below it has, so delay grows with width.
What is the difference between carry and overflow?
Carry out of the top bit means the unsigned sum did not fit. Signed overflow means the two's complement sum did not fit, and it is detected when the carry into the top bit differs from the carry out of it. 0111 + 0001 overflows as signed (7 + 1 is not -8) without any carry; 1111 + 0001 carries without overflowing (-1 + 1 = 0).
How many gates does a full adder need?
Five in the usual design: two XOR, two AND and one OR. A ripple-carry adder for n bits uses n full adders, so a 32-bit adder has 160 gates in this form.
Why do CPUs not use ripple-carry adders?
Speed. A 64-bit ripple-carry adder waits for up to 64 carries in sequence. Carry-lookahead and prefix adders (Kogge-Stone, Brent-Kung) compute the carries in parallel in about log2(n) gate levels, at the cost of more gates.
Related Tools
This tool runs entirely in your browser - nothing you enter is uploaded or stored.