# Half adder

*Adding two bits*

A half adder adds two single bits and produces a Sum (their XOR) and a Carry (their AND). It is the first arithmetic circuit, built directly from the logic gates you already have.

Group: Arithmetic
URL: https://digiwleea.wleeaf.dev/learn/halfadder/

At the end of the [XOR](https://digiwleea.wleeaf.dev/learn/xor/) lesson you saw the punchline: the sum of two bits is `A XOR B` and the carry is `A AND B`. This lesson cashes that in. You will place one [XOR](https://digiwleea.wleeaf.dev/learn/xor/) and one [AND](https://digiwleea.wleeaf.dev/learn/and/), both from your library, and you have built arithmetic.

The job: add two one-bit numbers. The catch is that `1 + 1 = 2`, and `2` does not fit in one bit. So the result needs **two** output bits: a **Sum** bit for the low-order result and a **Carry** bit for the overflow into the next column, exactly as you carry a 1 when adding on paper.

| A | B | S | C |
| --- | --- | --- | --- |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |

_Half adder truth table. S is the low bit of A+B; C is the high bit (the carry out)._

> **KEY:** Read the last row as binary: `1 + 1 = 10` (two). `S = 0` is the low bit, `C = 1` is the high bit. The carry is not an error; it is simply how binary addition overflows into the next column.

## Recognizing the gates

Compare each output column with truth tables you already know. `S` is `1` exactly when the inputs differ, which is [XOR](https://digiwleea.wleeaf.dev/learn/xor/). `C` is `1` only when both inputs are `1`, which is [AND](https://digiwleea.wleeaf.dev/learn/and/). So a half adder is nothing more than an XOR and an AND driven by the same two inputs.

1. Place an XOR part and an AND part on the canvas.
2. Run a wire from input `A` to the top pin of XOR and the top pin of AND.
3. Run a wire from input `B` to the bottom pin of XOR and the bottom pin of AND.
4. Label the XOR output `S` and the AND output `C`.

```
S = A XOR B
```

```
C = A AND B
```

_Circuit diagram: Completed half adder: one XOR for Sum, one AND for Carry, both driven by the same A and B. Open it in the lab and add the four combinations by hand._

> **TIP:** Notice that `A` and `B` each **fan out** into two gates, the branching you met in [wires and nets](https://digiwleea.wleeaf.dev/learn/wires-nets/). Start a new wire segment from any point on an existing wire to split a signal.

**Q (Try it):** Add `1 + 1` on the half adder. Read the result as a 2-bit binary number `C S`. What value is that, and why is the carry not an error?

**A:** `1 + 1`: `S = 1 XOR 1 = 0` and `C = 1 AND 1 = 1`. Read `C S` together: `10` in binary, which is **2**, the correct sum. The carry is the high bit of a 2-bit answer, exactly the `1` you carry into the next column when adding on paper. `1 + 1 = 2` simply does not fit in one bit.

> **KEY:** The half adder only handles the rightmost column of an addition, where nothing is carried in. To add real multi-bit numbers, every other column also needs a carry-*in*. Teaching it that third input is the [full adder](https://digiwleea.wleeaf.dev/learn/fulladder/), and a row of those is the adder inside your CPU.

### FAQ

**Q:** What is a half adder?

**A:** A half adder adds two single bits and produces two outputs: a Sum (`S = A XOR B`) and a Carry (`C = A AND B`). It is the simplest arithmetic circuit.

**Q:** Which gates make a half adder?

**A:** Just one [XOR](https://digiwleea.wleeaf.dev/learn/xor/) gate for the Sum and one [AND](https://digiwleea.wleeaf.dev/learn/and/) gate for the Carry, both driven by the same two inputs `A` and `B`.

**Q:** What is the difference between a half adder and a full adder?

**A:** A half adder adds only two bits, so it has no way to take a carry coming in from a previous column. A [full adder](https://digiwleea.wleeaf.dev/learn/fulladder/) adds three bits (two operands plus a carry-in), which is what lets you chain them to add multi-bit numbers.

**Q:** Why does a half adder need a carry output?

**A:** Because `1 + 1 = 2`, which does not fit in one bit. Read as binary, `1 + 1 = 10`: the Sum bit is the low `0` and the Carry bit is the high `1` that overflows into the next column.
