Interactive ALU Binary Adder

Watch how computers add numbers at the gate level

Explanation Simulator

How Computers Add Numbers

Every time your computer adds two numbers, it uses an Arithmetic Logic Unit (ALU) — a circuit built from simple logic gates. Each gate performs a tiny boolean operation (AND, OR, XOR), and by combining them, the ALU can add, subtract, and perform bitwise operations on binary numbers.

In Simple Terms

Binary addition works just like decimal addition, but with only two digits: 0 and 1. When you add 1 + 1, you get 10 in binary (that's 2 in decimal) — the "1" carries over to the next column, exactly like carrying in regular addition. A full adder is a small circuit that adds two bits plus a carry-in, producing a sum bit and a carry-out. Chain several together and you get a ripple carry adder that can add multi-bit numbers.

Logic Gates Used

XOR Outputs 1 when inputs differ. Used to compute the sum bit.
ABOut
000
011
101
110
AND Outputs 1 only when both inputs are 1. Used to detect carries.
ABOut
000
010
100
111
OR Outputs 1 when at least one input is 1. Used to combine carry signals.
ABOut
000
011
101
111

In Simple Terms: Why XOR for Addition?

If both inputs are 0, the sum is 0. If one is 1, the sum is 1. If both are 1, the sum is 0 with a carry. The sum bit is 1 only when the inputs differ — and that's exactly what XOR does. It's the natural gate for single-bit addition.

The Half Adder: A Simpler Building Block

Before understanding a full adder, consider the half adder — the simplest addition circuit. It adds two single bits with no carry-in:

A half adder handles the first bit position (where there's no incoming carry). For every subsequent bit, we need a full adder that also accepts a carry-in from the previous position.

Inside a Full Adder

Each full adder uses 2 XOR gates, 2 AND gates, and 1 OR gate:

The carry-out of each full adder feeds into the carry-in of the next, creating a "ripple" effect — hence the name ripple carry adder. Use the simulator below to watch this propagation in action.

Full Adder Truth Table

ABCinSumCout
00000
00110
01010
01101
10010
10101
11001
11111

In Simple Terms: The Ripple

Imagine adding 999 + 1 by hand. The carry ripples left through every 9, turning each into a 0 before finally settling. A ripple carry adder works the same way — each bit must wait for the carry from the previous one before it can produce its final sum. Simple and elegant, but slow for large numbers, which is why real CPUs use fancier carry logic like carry-lookahead adders.

How Subtraction Works: Two's Complement

How does an adder subtract? The trick is two's complement: instead of building a separate subtraction circuit, we reuse the same adder with a simple transformation.

To compute A − B:

  1. Invert every bit of B (flip 0s to 1s, and 1s to 0s). This gives the one's complement.
  2. Add 1 by setting the carry-in of the first adder to 1.
  3. Add normally: A + (inverted B) + 1 = A − B.

For example, in 4-bit: 7 − 3 → 0111 + 1100 + 1 = 0100 (4). Select SUB in the simulator to see this in action — notice the inverted B inputs and the carry-in set to 1.

Simulator

A
= 0
B
= 0
Ripple Carry Adder Circuit Click a full adder to see its internal gates
Full Adder Detail
Result
= 0
Carry Out
Overflow
Normal
Space Play/Pause   Step   Esc Reset
Step Info
Set your inputs and press Play or Step to begin the simulation.
Step: 0 / 0
Execution Trace