Truth tables: checking every possibility
A machine with three sensors has eight possible situations. How do you make sure it does the right thing in every single one?
About 30 min · 3 goals · Checked by automated tests; not yet reviewed by an educator
1.Why should I care?
A truth table is a machine's complete promise: for every possible input, here is the output. Engineers write them before building, and test against them afterwards, so that no situation is forgotten.
- ◇ Build a complete truth table for a gate or a small combination of gates.
- ◇ Know that n inputs give 2ⁿ rows.
- ◇ Use a truth table to check that a circuit matches a rule.
2.Predict
How many rows does a truth table need for a circuit with 3 inputs?
Guess first. Being wrong here is how the surprise works.
3.Discover
Open the digital logic lab. Build A AND (NOT B): put a NOT on input B and feed it into an AND with A. Fill in your truth table on paper first, then let the lab check every row. Which single row gives a 1?
Explorer 05 — Digital logic
Build answers out of ones and zeros
Every digital chip is built from a handful of simple gates. Flip the inputs to watch signals travel through a circuit, then wire your own gates to meet a target truth table.
- 1 (high)
- 0 (low)
- Unknown
- Inverting output
A single two-input gate. Change its type and watch the truth table change.
Inputs
Gates (1 of 8)
G1 = 0
Add a gate
Outputs
- Gates
- 1
- Depth
- 1
- Longest chain of gates a signal passes through
- Rows
- 4
- 2^2 input combinations
- Check
- —
| Set inputs | A | B | Y |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 1 | 0 | |
| 1 | 0 | 0 | |
| 1 | 1 | 1 |
State
Inputs A = 0, B = 0. Outputs Y = 0.
Inputs A = 0, B = 0. Outputs Y = 0.
How to read this
Signals flow left to right. Circles on the left are the inputs, boxes are gates and squares on the right are outputs. A thick bright wire carries a 1, a thin grey wire carries a 0, and each gate shows the value it outputs. A small circle on a gate's output means it inverts (NOT, NAND, NOR, XNOR).
The truth table lists every possible input combination and what the circuit outputs for each, so it describes the circuit completely. Two circuits with the same truth table are equivalent, however differently they are built. That is why NAND alone can make any other gate. Choose a row to set the inputs to it.
Assumptions & limitations
- Ideal logic: every wire is exactly 0 or 1. Real gates use voltage ranges (for example near 0 V and near 3.3 V or 5 V) and an input between them is undefined.
- Gates switch instantly here. Real gates take nanoseconds each, so a deeper circuit is slower, and outputs can glitch briefly while signals race through different paths.
- Only combinational circuits are allowed: no output may feed back into its own input. Feedback is how memory (latches and flip-flops) works, but it needs timing this model does not simulate, so loops are reported as an error.
- Gates here have one input (NOT) or two inputs. Real chips also have three- and four-input gates, and limits on how many inputs one output can drive (fan-out).
- Gate counts are a simple measure of size; real designs also weigh speed, power and the number of transistors per gate.
Can't use the interactive? Read a description instead
The digital logic lab lets you place gates, wire inputs to them and see a live truth table. For A AND (NOT B), the rows 00, 01, 10 and 11 give outputs 0, 0, 1 and 0: only A = 1 with B = 0 gives a 1.
4.Understand
List every input combination
Write the inputs as columns and count up in binary down the rows: for two inputs, 00, 01, 10, 11. Counting in binary guarantees you never miss or repeat a combination. Three inputs: 000 to 111, eight rows.
Work out the middle, then the output
For a combination like A AND (NOT B), add a helper column for NOT B first, then combine it with A. Doing one gate at a time, column by column, avoids mistakes.
| A | B | NOT B | A AND NOT B | |---|---|---|---| | 0 | 0 | 1 | 0 | | 0 | 1 | 0 | 0 | | 1 | 0 | 1 | 1 | | 1 | 1 | 0 | 0 |
A table is a test
To check a circuit, set the inputs for every row and compare its output with your table. If even one row disagrees, the circuit is wrong. This is exactly how the Tactiverge labs and Builds check your circuits: row by row, every row.
Explain it another way
A truth table is like a checklist for a robot butler: for every possible situation (raining or not, guests or not), it says exactly what to do. No situation is left to guesswork.
A truth table fully specifies a combinational function of n inputs with 2ⁿ rows. Two circuits are equivalent if, and only if, their truth tables match on every row, which is how NAND-only versions of gates are proved correct.
NOT (A AND B) and (NOT A) OR (NOT B) have identical tables (1, 1, 1, 0), so they are equal. This is one of De Morgan's laws. With 4 inputs a table has 2⁴ = 16 rows; with 10 inputs, 1,024 rows.
Before writing code for a machine's safety logic, engineers often write the full truth table with the client. Rows the client never thought about (such as 'both sensors broken') come to light early.
Worked example 1
Fill in the truth table for (NOT A) OR B and count the 1s.
Rows AB: 00 → NOT A = 1, so 1. 01 → 1. 10 → NOT A = 0, B = 0, so 0. 11 → B = 1, so 1. Three rows give 1.
Common mix-ups
- Testing a few input combinations is enough.
✓ A circuit is only proven correct when every row of its truth table matches. The one row you skipped may be the dangerous one.
5.Practice
Practice, not a test. Wrong answers get a hint and another try.
Practice 1 · a fresh version every time
Fill in the 4-row truth table for A XOR B (rows AB = 00, 01, 10, 11). How many rows give an output of 1?
Practice 2 · a fresh version every time
Fill in the 4-row truth table for (NOT A) OR B (rows AB = 00, 01, 10, 11). How many rows give an output of 1?
Practice 3
How many rows does a full truth table need for 4 inputs?
Practice 4
A mystery gate's truth table output column (rows 00, 01, 10, 11) is 0, 1, 1, 0. Which gate is it?
Practice 5
Why do engineers list truth table rows by counting in binary (00, 01, 10, 11)?
6.Apply it
Write the full 8-row truth table for a 'majority vote' circuit with inputs A, B and C: output 1 if at least two inputs are 1. How many rows give 1? (You'll meet this circuit again in the Sorting Machine Build.)
7.Reflect
Concepts: Logic gates and Boolean algebra · Testing and debugging