Logic gates and truth tables
▶ Watch the video lessonShort, exam-focused explanation of this topic on the CS with Aamir YouTube channel.A logic gate is an electronic component that takes one or more binary inputs (0 or 1) and produces a single binary output. Computers are built from millions of these gates. You need to know six gates, their truth tables, and how to work out the output of a circuit made from several gates.
The six logic gates
| Gate | Output is 1 when… | Boolean expression |
|---|---|---|
| NOT | the input is 0 (it inverts the input) | X = NOT A |
| AND | both inputs are 1 | X = A AND B |
| OR | at least one input is 1 | X = A OR B |
| NAND | NOT both inputs are 1 (opposite of AND) | X = A NAND B |
| NOR | both inputs are 0 (opposite of OR) | X = A NOR B |
| XOR | the inputs are different | X = A XOR B |
Truth table for the two-input gates
| A | B | AND | OR | NAND | NOR | XOR |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
A quick way to remember: NAND and NOR are simply AND and OR with the output inverted, and XOR is like OR except that 1 and 1 gives 0.
How many rows does a truth table need?
A truth table needs 2n rows, where n is the number of inputs: 2 inputs → 4 rows, 3 inputs → 8 rows. List the inputs in binary counting order (000, 001, 010 … 111) so that you don't miss a combination.
Worked example: a logic circuit
Complete the truth table for X = (A AND B) OR (NOT C). Work it out in stages by adding a column for each gate:
| A | B | C | A AND B | NOT C | X |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 1 |
From a problem statement to a circuit
Exam questions often describe a real situation, for example: "An alarm (X) sounds if the door is open (A = 1) AND the system is switched on (B = 1), OR if the panic button is pressed (C = 1)." Turn each condition into part of an expression – here X = (A AND B) OR C – then draw one gate for each operator.
Exam tips
- Learn the shape of each gate symbol: NOT is a triangle with a small circle, and the small circle always means "inverted".
- Use working columns for each gate – it is much easier to find mistakes.
- Each gate in the exam has at most two inputs, except NOT, which has one.
- Check the final column against the question: if a sentence says "and", it is usually an AND gate.