# Adding 8-bit numbers

*The ripple-carry adder*

A ripple-carry adder chains eight full adders, each carry-out feeding the next adder's carry-in, so it adds two 8-bit numbers in a single pass. It is the arithmetic core the ALU is built around.

Group: Processor
URL: https://digiwleea.wleeaf.dev/learn/adder8/

The [full adder](https://digiwleea.wleeaf.dev/learn/fulladder/) adds three bits, `A`, `B`, and a carry-in, and produces a sum bit and a carry-out. That is one column of an addition. To add two whole [8-bit numbers](https://digiwleea.wleeaf.dev/learn/buses/) you do what you do on paper: add the columns right to left, carrying into the next column as you go. In hardware that means **eight full adders in a row**, with each stage's carry-out wired into the next stage's carry-in. See the same carry chain on real numbers in the [binary calculator](https://digiwleea.wleeaf.dev/tools/binary-calculator/), or step through the ripple carry column by column in the [interactive binary addition walkthrough](https://digiwleea.wleeaf.dev/tools/binary-addition/).

## Carry ripples left, column by column

Number the bits `0` (least significant) to `7` (most significant). Stage `i` adds `Ai`, `Bi`, and the carry coming from stage `i-1`. Its sum bit is `Si`; its carry-out goes on to stage `i+1`. The very first stage has no column to its right, so its carry-in is the external `CIN` (tie it to `0` for plain addition). The last stage's carry-out is `COUT`, the ninth bit of the answer, which signals overflow past 8 bits.

```
Si, carry_out = FULLADDER(Ai, Bi, carry_in),   carry_in(0) = CIN,   carry_in(i) = carry_out(i-1)
```

1. Place eight [full adders](https://digiwleea.wleeaf.dev/learn/fulladder/) in a row, one per bit position.
2. Feed `Ai` and `Bi` into stage `i`, and read its sum on `Si`.
3. Wire each stage's carry-out into the next stage's carry-in: stage 0 to stage 1, stage 1 to stage 2, and so on.
4. Tie stage 0's carry-in to `CIN` (use `0` for addition); the top stage's carry-out is `COUT`.

> **KEY:** Worked example: `00001111 + 00000001` (15 + 1). Stage 0 adds `1 + 1 = 10`, so `S0 = 0` and it carries `1`. That carry ripples: stage 1 adds `1 + 0 + 1 = 10` again, carry on. The carry keeps rippling up through the four low `1`s until stage 4 adds `0 + 0 + 1 = 1` with no carry. The result is `00010000`, which is 16. The carry literally walked left through the stages, one column per step.

_Circuit diagram: An 8-bit ripple-carry adder (ADD8): eight full adders with the carry chained from CIN through to COUT. Inputs A0-A7 and B0-B7 are the two operands; S0-S7 is the sum. Open it in the lab, set two bytes, and read the sum (watch COUT light up when the total passes 255)._

**Q (Try it):** On the 8-bit adder, set `A = 200` and `B = 100` (with `CIN = 0`). The true sum is 300, which does not fit in 8 bits. What do `S0`-`S7` read, and what does `COUT` do?

**A:** `300` is `1 0010 1100` in binary: nine bits. The low eight, `0010 1100` (`44`), appear on `S0`-`S7`, and the ninth bit overflows into `COUT = 1`. So `S` shows `44` and `COUT = 1` flags that the real answer is `256 + 44 = 300`. `COUT` is the carry out of the top column, the overflow signal.

> **TIP:** The cost of this simplicity is **delay**. The top sum bit cannot settle until the carry has rippled through all eight stages below it, so a wide ripple adder is slow. Real CPUs use cleverer carry-lookahead adders to compute the carries in parallel, but they compute the exact same sum. Ripple-carry is the right place to start: it is correct, and it is just the full adder you already built, eight times.

> **KEY:** An adder only adds. But with one [XOR](https://digiwleea.wleeaf.dev/learn/xor/) trick on the `B` input you can make this very same hardware **subtract** as well, which is the next lesson, [negative numbers and subtraction](https://digiwleea.wleeaf.dev/learn/subtract/). Add plus subtract on one block is the heart of the [ALU](https://digiwleea.wleeaf.dev/learn/alu/).

### FAQ

**Q:** How does a ripple-carry adder work?

**A:** A **ripple-carry adder** chains eight [full adders](https://digiwleea.wleeaf.dev/learn/fulladder/), one per bit position, with each stage's carry-out wired into the next stage's carry-in. It adds two 8-bit numbers the way you add on paper: column by column, right to left, carrying into the next column. The rightmost stage's carry-in is tied to `0` for plain addition.

**Q:** Why is it called "ripple" carry?

**A:** Because the carry literally walks left through the stages, one column per step. When you add `15 + 1`, the carry out of stage 0 ripples up through the four low `1`s until a stage adds with no carry. The top sum bit cannot settle until the carry has rippled through all stages below it.

**Q:** What does the carry-out (COUT) of an 8-bit adder mean?

**A:** `COUT` is the carry out of the top column, the ninth bit of the answer, so it signals overflow past 8 bits. Adding `200 + 100 = 300` does not fit: the low eight bits show `44` on `S0`-`S7` and `COUT = 1` flags that the real total is `256 + 44 = 300`.

**Q:** Why are ripple-carry adders slow?

**A:** The cost of their simplicity is **delay**: the top sum bit cannot settle until the carry has rippled through all eight stages, so a wide ripple adder is slow. Real CPUs use carry-lookahead adders that compute the carries in parallel, but they produce the exact same sum. Ripple-carry is the right starting point: correct, and just the full adder you already built, eight times.
