Truth Tables
A truth table must list every possible combination of input values, so the number of rows depends on how many inputs the expression has.
For n inputs there are 2 to the power of n possible combinations, so each extra input doubles the number of rows. Adding an input splits every row you already had into two: one where the new input is 0, and one where it is 1.
| Inputs | Rows needed | Combinations |
|---|---|---|
| 1 | 2 | 0, 1 |
| 2 | 4 | 00, 01, 10, 11 |
| 3 | 8 | 000, 001, 010, 011, 100, 101, 110, 111 |
A three-input truth table therefore has eight rows, not six. With only six rows you have left two combinations out, so the table is incomplete and cannot show what the expression does in those cases.
The combinations in the table are listed in binary counting order, which is a common way to fill the input columns. Counting upwards like this makes the table easy to check, because you can see straight away when a combination has been skipped.
For example, a bike alarm might take three inputs: wheel moving (W), alarm armed (A) and key inserted (K). With three inputs you need eight rows, and every row gets its own set of values for W, A and K before you work out the output for that row.
The rows do not have to follow binary order. Any order works as long as every possible combination appears exactly once and none is repeated, so shuffling the eight rows of a three-input table still gives a correct table.
A two-input truth table shows the output of an expression such as A AND B for every combination of its two inputs. Two inputs give 2 × 2 = four rows: 00, 01, 10 and 11.
AND gives 1 only when both inputs are 1. OR gives 1 when at least one input is 1, including when both are, so it is 0 only in the row where both inputs are 0.
| A | B | A AND B | A OR B |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 |
A quick check: the AND column has a single 1, in the last row, and the OR column has a single 0, in the first.
NOT works on one value, turning 1 into 0 and 0 into 1. In a two-input expression it applies to just the input or bracket it is written in front of. For A AND NOT B, work out NOT B in its own column first, then AND it with A.
| A | B | NOT B | A AND NOT B |
|---|---|---|---|
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
For example, a games console lets you play online when you are signed in (A) and you are NOT banned (B). Only the row where A is 1 and B is 0 gives 1, so that is the only situation in which you can play online.
When a Boolean expression contains more than one operator, it is not worked out from left to right. A fixed order called operator precedence decides which part is applied first, so the expression always keeps one clear meaning.
| Priority | Operator | What it does |
|---|---|---|
| 1 | Brackets | Work out whatever is inside them before anything outside them |
| 2 | NOT | Inverts a single input, or the result of a bracketed expression |
| 3 | AND | Gives 1 only when both of its inputs are 1 |
| 4 | OR | Gives 1 when at least one of its inputs is 1 |
Brackets override the normal order, so a bracketed OR is settled before an AND sitting outside it. Logical expressions are written with the words AND, OR and NOT in capitals, and parentheses show clearly which parts are grouped together.
A club meets when F (field free) AND NOT R (raining) OR H (hall booked). NOT is applied before AND, and AND before OR, so the expression really means (F AND (NOT R)) OR H. With F = 1, R = 1 and H = 0: NOT R is 0, F AND 0 is 0, and 0 OR H is 0, so the club does not meet.
Putting NOT in front of brackets works differently. To evaluate NOT (F AND R), work out F AND R first and then invert that single result: if F AND R came to 1 then NOT (F AND R) is 0, and if it came to 0 the answer is 1. This is not the same as (NOT F) AND R, which inverts only F before the AND is applied.
A truth table for three inputs lists every combination of those inputs next to the output of the logical expression. The expression can mix AND, OR and NOT, so work out each row from all three values together, not from a single input alone.
AND gives 1 only when every input is 1, so with three inputs all three must be 1. A single 0 anywhere is enough to make the output 0. OR is the mirror image: it gives 0 only when all three inputs are 0, and one 1 is enough to make the output 1. OR is inclusive, so two or even three 1s also give 1.
Compare A = 1, B = 1 and C = 0. A AND B AND C is 0 because C fails, while A OR B OR C is 1 because two of the inputs already succeed.
Read the problem and pin down what the inputs are, what the output is, and how they combine. A laptop's cooling fan runs fast when a game is running OR the processor is hot, but not when quiet mode is on. The inputs are game running (G), processor hot (H) and quiet mode (Q), and the output is fan fast (F), giving F = (G OR H) AND NOT Q.
Then apply the operators to each of the eight rows: the bracket is worked out first, and NOT Q flips that one input only. Where G = 1, H = 0 and Q = 0, the bracket gives 1 and NOT Q gives 1, so F = 1. Change Q to 1 and F becomes 0 however hard the game is working, because quiet mode overrides the other two inputs.
| G | H | Q | F = (G OR H) AND NOT Q |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
When an expression mixes several operators, a truth table can show the working rather than only the answer. Each intermediate column holds the value of one sub-expression, so the final column only combines values you have already worked out.
For example, a school greenhouse has a motor that opens the roof vent. It runs when the air is too warm OR too damp, but only when the vent is not already open. With A = too warm, B = too damp and C = vent already open, the rule is Q = (A OR B) AND NOT C. The bracketed OR gives you the first intermediate column, and the NOT gives you the second.
| A | B | C | A OR B | NOT C | (A OR B) AND NOT C |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 |
| 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 |
The last column may be headed with the full expression, as above, or with an output letter such as Q. Either is fine as long as the heading matches what the column contains.
Intermediate columns keep each step visible, so a slip is easy to spot and fix before it affects the final answer.
A truth table usually starts with a Boolean expression and works out the output. You can use it in reverse: start with the output column and work out an expression that produces it. Compare the pattern of 1s and 0s with the rules for AND, OR and NOT.
A column that is 1 only where both inputs are 1 matches the AND of those inputs. A column that is 1 where either input, or both, is 1 matches the OR of those inputs. A column that is the opposite of an input matches NOT applied to that input.
| A | B | Q1 | Q2 | Q3 |
|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 1 | 0 |
Q1 is 1 only where A is 1 and B is 0, so Q1 = A AND (NOT B). Q2 is 0 only where A is 1 and B is 0; it is 1 whenever B is 1 or A is 0, so Q2 = (NOT A) OR B. OR is inclusive, so it still gives 1 when both parts are true. Q3 is 1 only when both A and B are 0, so Q3 = NOT (A OR B). If either input is 1, A OR B is 1, so NOT makes the output 0.
Do not stop once you have matched the rows containing 1. Test your expression on every row, including those where the output is 0. A wrong expression often agrees on the 1s but fails on a 0.
For example, you might guess Q1 = A because Q1 is 1 on the row A=1, B=0. But Q1 is 0 on the row A=1, B=1, and A alone would give 1 there. Checking the 0 rows has ruled out the wrong expression and shown that Q1 must also require B to be 0, so Q1 = A AND (NOT B).
In an exam, a truth table is marked on two things: the values you write and the way you write them. The examiner compares each row of your table with the expected values, so anything that cannot be read clearly as true or false loses marks even when your reasoning was right.
Choose 1 and 0 or True and False, then stay with that choice in every column. Mixing them, such as 1 in one column and False in the next, makes your table hard to follow and can cost marks. T and F, and On and Off, are also accepted, because each pair gives one clear value for true and one clear value for false. Ticks and crosses are not accepted, so use one of these pairs instead. Do not invent a symbol of your own: it is not a truth value, so there is nothing for the examiner to compare with the expected 1.
The input columns are usually worth marks on their own, separate from the output column. A table with a flawless output column but a missing input combination therefore still drops marks, because every possible combination of the inputs has to appear exactly once. Near the end of the exam, read across the input columns row by row and check that no combination repeats another.
If a value in an input column is wrong, the rest of that row is not automatically lost. The examiner applies the logical operators to the values you actually wrote, and when your output fits those values you keep the output mark. This is called a carry-through mark. Suppose the expression is R OR NOT S and one row should read R = 0, S = 1, so the output is 0. You write S = 0 by mistake, then write the output as 1. Applying OR and NOT to the values you actually wrote gives 0 OR NOT 0, which is 1, so the output value is still marked correct, while the input value itself is marked wrong.