LearnGates

Logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR

A logic gate is a tiny circuit that takes one or more inputs, each 0 or 1, and gives an output that is also 0 or 1. Computers are made of millions of them: every addition, every comparison and every bit of memory comes down to gates.

There are seven basic gates. Each one is described by a truth table: the list of every possible combination of inputs, with the output the gate gives for it. Click the inputs below to try each gate.

AND

Formula Y = A · B   Y = A AND B

Truth table of AND
ABY
000
010
100
111

Try it Click the inputs to change them.

Y0

OR

Formula Y = A + B   Y = A OR B

Truth table of OR
ABY
000
011
101
111

Try it Click the inputs to change them.

Y0

NOT

Formula Y = Ā   Y = NOT A

Truth table of NOT
AY
01
10

Try it Click the inputs to change them.

Y1

NAND

Formula Y = (A · B)‾   Y = A NAND B

Truth table of NAND
ABY
001
011
101
110

Try it Click the inputs to change them.

Y1

NOR

Formula Y = (A + B)‾   Y = A NOR B

Truth table of NOR
ABY
001
010
100
110

Try it Click the inputs to change them.

Y1

XOR

Formula Y = A ⊕ B   Y = A XOR B

Truth table of XOR
ABY
000
011
101
110

Try it Click the inputs to change them.

Y0

XNOR

Formula Y = (A ⊕ B)‾   Y = A XNOR B

Truth table of XNOR
ABY
001
010
100
111

Try it Click the inputs to change them.

Y1

Why only 0 and 1?

Inside a chip, a wire is either at a low voltage (0) or a high voltage (1). With only two values, circuits are simple, reliable and cheap to make. The rules for combining 0s and 1s are called Boolean algebra, after the mathematician George Boole.

In what order should I learn them?

Start with NOT, AND and OR: they behave like the everyday words. Then NAND and NOR, which are AND and OR with the output turned upside down, and XOR, which is 1 when its inputs differ. Then the lessons show how gates combine into adders, memory and counters.