The seven core gates

A logic gate takes one or two binary inputs and produces a single binary output. Click any gate name to switch the demo. Toggle the input switches to drive the gate live — watch the wires light up.

AND gate

A
B
Output
Boolean expression
A · B
Reads as
"A AND B"

Truth table

A truth table lists every input combination and the resulting output. Current row is highlighted.

Why these seven?

AND, OR, and NOT are the functionally complete set — every other gate (and every digital circuit ever built) can be assembled from them. NAND alone is also complete, which is why NAND chips are everywhere: simpler manufacturing, fewer transistors, and you can wire any logic from them. XOR is the workhorse of arithmetic — it's the sum bit of a binary adder.

Combine gates

Wire two gates together. The output of the first feeds an input of the second. Toggle the three input switches and watch how the chain evaluates.

Stage 1
Stage 2
A
B
C
Final
Expression:

Full truth table for the chain

Half adder & full adder

An adder is the first useful circuit you can build from gates. A half adder sums two single bits using one XOR (sum) and one AND (carry). A full adder chains two half adders plus an OR to also accept a carry-in — it's the building block of every CPU's arithmetic unit.

Half adder

Sum = A XOR B · Carry = A AND B
A
B
Sum
Carry

Full adder

Sum = A XOR B XOR Cin · Cout = (A AND B) OR (Cin AND (A XOR B))
A
B
Cin
Sum
Cout
From here, an n-bit adder. Chain n full adders end-to-end, feeding each Cout into the next Cin. Two 4-bit numbers add in 4 cells. This ripple-carry adder is the simplest CPU integer unit. Faster designs (carry-lookahead, prefix adders) compute carries in parallel for speed.

Gate cheat sheet

AND

Output is 1 only when both inputs are 1. Think of switches in series — current must pass through both. Y = A · B

OR

Output is 1 when either input (or both) is 1. Think of switches in parallel. Y = A + B

NOT (inverter)

The only single-input gate. Output is the opposite of the input. Drawn with a small bubble on the output. Y = ¬A

NAND

"Not AND" — output is 0 only when both inputs are 1. Universal: every other gate can be built from NANDs alone. The most common gate inside real chips. Y = ¬(A · B)

NOR

"Not OR" — output is 1 only when both inputs are 0. Also universal on its own. The first integrated circuits used NOR for memory cells. Y = ¬(A + B)

XOR (exclusive OR)

Output is 1 when inputs differ. Used for the sum bit in adders, parity checks, simple ciphers, and graphics. Y = A ⊕ B

XNOR (equivalence)

"Not XOR" — output is 1 when inputs are the same. Used in equality comparators. Y = ¬(A ⊕ B)

De Morgan's laws

Two ways to "push the NOT through":

  • ¬(A · B) = ¬A + ¬B "NOT (A AND B) = NOT-A OR NOT-B"
  • ¬(A + B) = ¬A · ¬B "NOT (A OR B) = NOT-A AND NOT-B"

These rules let you simplify circuits — you can replace a NAND with an OR-of-inverters, swap gates for cheaper layouts, and reason about logic algebraically.

Symbol shapes (US "distinctive" style)

0
Score
0
Streak
%
Question