Truth Tables
A logic gate is a promise: "given these inputs, I will give you that output."
But a promise is only useful if you know it holds for every case. A
truth table is how we pin that promise down. It is a simple grid that lists
every possible combination of inputs, one per row, and shows the output beside
each one. Nothing is left to guesswork — the table describes the gate completely.
Because a logic input is always either 0 (false, off) or
1 (true, on), the combinations are easy to count. One input can be
0 or 1 — that's two rows. Two inputs give
four rows. Get into the habit of writing them in binary-counting order —
00, 01, 10, 11 — and you will never miss a case.
The three tables you must know
Every logic expression you meet at GCSE is built from just three gates:
AND, OR and NOT. Learn their truth tables
and you can work out anything else. In each grid, the shaded right-hand column is the
output; the plain columns on the left are the inputs.
AND — the output is 1 only when
both inputs are 1 (think: "A and B must both be true").
OR — the output is 1 when at least one
input is 1 (it is 0 only when both are off).
NOT — it has just one input, and it simply flips it:
0 becomes 1 and
1 becomes 0. With one input there are only
two rows.
Building a combined expression, column by column
Real questions rarely give you a single gate. You'll see something like
A \text{ AND } (\text{NOT } B). The trick is to not
try to do it all at once. Add a column for each intermediate step, work that column out
first, and only then combine columns to reach the final answer.
Here we build A \text{ AND } (\text{NOT } B). Start with the two input
columns, add a \text{NOT } B column (just flip B), then AND columns
A and \text{NOT } B together. Press play to
watch each column appear.
Reading the finished table: the output is 1 on exactly one row —
when A = 1 and B = 0 — because that is the
only row where A is on and \text{NOT } B
is also on. Every other combination gives 0.
How many rows? The 2^n rule
The most important fact about truth tables is how their size grows. Each input doubles the number
of combinations, so for n inputs there are exactly
2^n rows:
\text{number of rows} = 2^{\,n}
| Inputs (n) |
Rows (2^n) |
| 1 | 2 |
| 2 | 4 |
| 3 | 8 |
| 4 | 16 |
So a table for 3 inputs needs 8 rows —
list them in binary order: 000, 001, 010, 011, 100, 101, 110, 111.
This doubling is also why a circuit with lots of inputs is hard to test by hand: at
10 inputs you would already need 1024 rows!
Two classic mistakes cost easy marks:
1. Missing a row. With two inputs you must have all four rows —
00, 01, 10, 11 — not three. Write them in strict binary-counting
order every time (like an odometer: increase the right-hand column first). That way you
physically can't skip a combination, and it's obvious if you have too few or too many rows for
your 2^n.
2. Jumping to the final column. For an expression like
A \text{ AND } (\text{NOT } B), don't try to fill the answer straight
from A and B in your head. Fill the
intermediate column (\text{NOT } B) first, then combine.
Working left-to-right through the columns turns a tricky expression into a chain of tiny,
reliable steps.
The idea is older than computers. In the early 1900s, logicians wrote
1/0 as true/false
(or T/F) to reason about statements like "it is raining AND I have an umbrella". A truth table
laid out whether the whole statement was true for every combination of the smaller statements.
Decades later, engineers realised a 1/0
wire was exactly the same thing — so the logician's truth table became the engineer's tool for
designing circuits. Same table, two worlds.
Let a program build the table for you
A computer can generate a truth table by looping over every input combination — which is just
counting in binary. This program loops A and
B through 0 and 1
and prints the AND, OR and combined A \text{ AND } (\text{NOT } B)
outputs. Press Run and compare it with the tables above.
console.log("A B | AND OR A AND (NOT B)");
console.log("----+-----------------------");
for (let A = 0; A <= 1; A++) {
for (let B = 0; B <= 1; B++) {
const AND: number = A && B ? 1 : 0;
const OR: number = A || B ? 1 : 0;
const combined: number = A && !B ? 1 : 0;
console.log(A + " " + B + " | " + AND + " " + OR + " " + combined);
}
}
Notice the nested loops go 00, 01, 10, 11 — the same binary-counting
order you write by hand. Add a third input and a third loop, and it would print all
8 rows automatically.