Constructing and analysing truth tables
In one sentence: Truth tables map every possible binary input combination (
2^nrows) to intermediate and final outputs, connecting logic diagrams, real-world specifications, Boolean expressions, and simplified circuits using Karnaugh maps or Boolean algebra.
What you will learn
By the end of this lesson, you should be able to:
- Construct complete truth tables (up to 3 inputs) to predict the output of multi-gate logic circuits.
- Translate natural-language problem descriptions into input variables, truth tables, and Boolean expressions.
- Apply Boolean operator precedence (
NOT, thenAND/NAND, thenOR/NOR/XOR/XNOR) accurately. - Derive Sum-of-Products (SOP) Boolean expressions from truth tables and logic diagrams.
- Simplify Boolean expressions using 2-input and 3-input Karnaugh maps (including Gray-code ordering and edge wraparound) as well as Boolean algebra laws.
Before you begin
Make sure you know the input-output behaviour and Boolean symbols for all seven logic gates from Purpose and use of logic gates (A1.2.3). Recall Gray code from How binary is used to store data (A1.2.2): a 2-bit ordering (00, 01, 11, 10) in which each adjacent pattern differs by only 1 bit.
Key words
| Term | Simple meaning |
|---|---|
| Input combination | One specific assignment of 0s and 1s to every input variable, forming one row of a truth table. |
| Intermediate value | A temporary named signal (P, Q, R) representing a single gate's output inside a multi-gate circuit. |
| Operator precedence | The fixed order (NOT, then AND or NAND, then OR, NOR, XOR, or XNOR) for evaluating unparenthesized expressions. |
| Sum-of-Products (SOP) | A Boolean expression formed by ORing (+) AND-terms (minterms), where each AND-term matches one 1 row in the truth table. |
| Karnaugh map (K-map) | A grid arranged in Gray-code order that exposes adjacent 1 cells for rapid visual Boolean simplification. |
| Boolean simplification | Reducing the number of terms and gates in an expression while keeping its truth table identical. |
The idea, step by step
1. Sizing and ordering a truth table (2^n rows)
When a circuit or problem has n binary inputs, each input can take 2 values (0 or 1). Therefore, the total number of distinct input rows is:
Number of rows =
2^n
1input (A):2^1 = 2rows2inputs (A, B):2^2 = 4rows3inputs (A, B, C):2^3 = 8rows
To guarantee you never miss or duplicate a row in a 3-input (A, B, C) table, populate inputs using binary counting from 000 (0) to 111 (7):
- Rightmost column (
C): Alternate0, 1, 0, 1, ...every 1 row. - Middle column (
B): Alternate0, 0, 1, 1, 0, 0, 1, 1every 2 rows. - Leftmost column (
A): Alternate0, 0, 0, 0, 1, 1, 1, 1every 4 rows.
2. Predicting the output of a multi-gate logic circuit
Evaluating a multi-stage circuit in your head invites mistakes. Instead, add one intermediate column (P, Q, R, ...) for each internal gate output moving left-to-right from the inputs toward the final output X.
Suppose a 3-input circuit connects four gates:
- Gate 1 (
XOR): takesAandBto produce intermediate signalP = A ⊕ B - Gate 2 (
OR): takesBandCto produce intermediate signalQ = B + C - Gate 3 (
NAND): combinesPandQto produce intermediate signalR = NOT(P · Q) - Gate 4 (
AND): combinesRand inputCto produce final outputX = R · C
Evaluate one column at a time across all 8 rows:
A | B | C | P = A ⊕ B | Q = B + C | R = NOT(P · Q) | X = R · C |
|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 1 | 0 |
0 | 0 | 1 | 0 | 1 | 1 | 1 |
0 | 1 | 0 | 1 | 1 | 0 | 0 |
0 | 1 | 1 | 1 | 1 | 0 | 0 |
1 | 0 | 0 | 1 | 0 | 1 | 0 |
1 | 0 | 1 | 1 | 1 | 0 | 0 |
1 | 1 | 0 | 0 | 1 | 1 | 0 |
1 | 1 | 1 | 0 | 1 | 1 | 1 |
Reading down column X immediately tells you the circuit outputs 1 only for (0, 0, 1) and (1, 1, 1).
3. Truth tables from problem descriptions
Real-world specifications describe rules in plain English. Convert a specification to a truth table in four steps:
- Identify input variables: Represent every binary condition as an input variable (
A,B,C) and state clearly what1and0mean for each. - List all
2^ninput rows: Order the input combinations using binary counting. - Break compound conditions into intermediate columns: Create columns (
P,Q) matching keywords such as "not" (NOT), "both / and / provided that" (AND), "either / or" (OR), and "only one of" (XOR). - Compute the final output column: Evaluate
Xfor every row.
4. Boolean expressions and operator precedence
Every truth table and circuit translates directly into a Boolean algebra expression. Parentheses always force their inner expression to be evaluated first, just like brackets in arithmetic. When no parentheses clarify grouping, Boolean algebra applies a strict order of operations:
NOT(highest priority; applies only to the variable or parenthesized group immediately under or after it)ANDandNANDOR,NOR,XOR, andXNOR(lowest priority)
For instance, in X = NOT A · B + C, NOT A runs first, then (NOT A) · B, and finally + C. Writing (NOT A · B) + C evaluates differently from NOT(A · B) + C, so always verify operator precedence carefully.
You can also read an unsimplified Sum-of-Products (SOP) Boolean expression directly from any completed truth table:
- Find every row where output
X = 1. - For each such row, write an
ANDterm containing every input variable: keep variableVif its value in that row is1, orNOT V(V̅) if its value is0. - Connect all those
ANDterms withOR(+).
5. Simplifying expressions with Karnaugh maps (K-maps)
Unsimplified SOP expressions often waste hardware gates. A Karnaugh map (K-map) reorganizes a truth table into a 2D grid so visually adjacent 1s reveal variables that cancel out.
Two-input K-maps (2 × 2)
Place A along the side (0, 1) and B across the top (0, 1). Each cell holds the truth table output for that (A, B) pair.
For example, consider X = (A · B) + (A · NOT B):
A = 1, B = 1: place1in the bottom-right cell.A = 1, B = 0: place1in the bottom-left cell.- All other cells are
0.
A \ B | 0 | 1 |
|---|---|---|
0 | 0 | 0 |
1 | 1 | 1 |
Across the single horizontal pair along row A = 1, variable A stays constant (1) while B flips between 0 and 1, so B cancels out and the entire expression simplifies to X = A.
Three-input K-maps (2 × 4) and Gray-code ordering
Put one variable (for example, C) along the rows (0, 1) and two variables (AB) across the four columns in Gray-code order:
00,01,11,10
Note that 11 comes before 10. That ensures adjacent columns change by exactly one bit: going from 01 to 11 flips only A, going from 11 to 10 flips only B, and wrapping from the right edge 10 back to the left edge 00 flips only A.
The six K-map grouping rules
When circling or boxing groups of 1s to simplify a K-map:
- Powers of 2 only: Every group must contain
1, 2, 4, 8(or16) adjacent1s, never3or6. - Rectangular or square shapes only: No L-shapes or staggered zig-zags.
- No diagonals: Cells are adjacent only horizontally or vertically (including wrapping across opposite left/right edges, or top/bottom in 4-input maps).
- Make groups as large as possible: Larger groups eliminate more variables (
1cell eliminates0variables;2cells eliminate1;4cells eliminate2). - Overlaps are permitted and helpful: Re-using an already covered
1is encouraged whenever it creates a larger power-of-two group. - Minimize the total number of groups: Cover all
1s using as few valid groups as possible; never add a redundant group whose1s are all already covered.
Reading the simplified expression from groups
For each group:
- Inspect every variable (
A,B,C):- If its value stays
1in every cell of the group, includeV. - If its value stays
0in every cell of the group, includeNOT V(V̅). - If its value takes both
0and1inside the group, discard that variable.
- If its value stays
- Join all retained variables inside one group with
AND(·), and join separate groups withOR(+).
6. Algebraic Boolean simplification laws
You can also simplify Boolean expressions directly using algebra rules:
| Law name | AND form | OR form |
|---|---|---|
| Identity | A · 1 = A | A + 0 = A |
| Null / Dominance | A · 0 = 0 | A + 1 = 1 |
| Idempotent | A · A = A | A + A = A |
| Complement | A · NOT A = 0 | A + NOT A = 1 |
| Double negation | NOT(NOT A) = A | N/A |
| Distributive | A · (B + C) = A · B + A · C | A + (B · C) = (A + B) · (A + C) |
| Absorption | A · (A + B) = A | A + (A · B) = A |
| De Morgan's laws | NOT(A · B) = (NOT A) + (NOT B) | NOT(A + B) = (NOT A) · (NOT B) |
Factoring and applying Complement (B + NOT B = 1) with Identity (A · 1 = A) is the algebraic mirror of boxing two adjacent K-map cells: A · B + A · NOT B = A · (B + NOT B) = A · 1 = A.
Worked example
Part A: Problem description to truth table and Boolean expression
Specification: A laboratory fume-hood alarm fan (X = 1) runs whenever emergency lockdown is not pressed (A = 0) and either the gas sensor triggers (B = 1) or the manual purge switch is on (C = 1).
- Define inputs and intermediates:
A= lockdown active (1) / not active (0); we needQ = NOT A.B= gas detected (1/0);C= purge switch on (1/0); we needP = B + C.- Final output:
X = Q · P = (NOT A) · (B + C).
- Truth table (
2^3 = 8rows):
A | B | C | Q = NOT A | P = B + C | X = Q · P |
|---|---|---|---|---|---|
0 | 0 | 0 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 1 | 1 |
0 | 1 | 0 | 1 | 1 | 1 |
0 | 1 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 0 | 1 | 0 |
1 | 1 | 0 | 0 | 1 | 0 |
1 | 1 | 1 | 0 | 1 | 0 |
Result: X = 1 in 3 out of 8 rows (all cases where A = 0 and at least one of B, C is 1).
Part B: Three-input K-map with edge wrapping (and algebraic cross-check)
Simplify:
Y = (NOT A · NOT B · NOT C) + (NOT A · NOT B · C) + (A · NOT B · NOT C) + (A · NOT B · C) + (A · B · C)
- Plot all five
1s onto the 3-input K-map (Cdown rows,ABin Gray order across columns):
C \ AB | 00 (NOT A·NOT B) | 01 (NOT A·B) | 11 (A·B) | 10 (A·NOT B) |
|---|---|---|---|---|
0 | 1 | 0 | 0 | 1 |
1 | 1 | 0 | 1 | 1 |
- Group adjacent
1s as large as possible:- Group 1 (size 4, horizontal wraparound): Column
AB = 00(rows0, 1) and columnAB = 10(rows0, 1) wrap around the left and right edges to form a2 × 2square of 41s. Across{00, 10}andC ∈ {0, 1},Aflips between0and1,Cflips between0and1, andB = 0stays constant, giving the termNOT B. - Group 2 (size 2, overlapping horizontal pair): The single remaining
1at(C=1, AB=11)overlaps horizontally with(C=1, AB=10)to form a 2-cell group (better than a solo 1-cell group). Across(C=1, AB=11)and(C=1, AB=10),Bflips between1and0whileA = 1andC = 1stay constant, giving the termA · C.
- Group 1 (size 4, horizontal wraparound): Column
- Simplified expression:
Y = (NOT B) + (A · C). - Algebraic cross-check: Factoring
(NOT B)from the first four terms leaves(NOT B) · ((NOT A · NOT C) + (NOT A · C) + (A · NOT C) + (A · C)) = NOT B · 1 = NOT B. Then by the Boolean distributive lawNOT B + (A · B · C) = (NOT B + B) · (NOT B + A · C) = 1 · (NOT B + A · C) = (NOT B) + (A · C). Both methods give the identical minimal result.
Check your understanding
- How many rows are needed in a truth table with
4binary inputs (A, B, C, D)? - Without parentheses, which operation executes first in
X = A + NOT B · C, and what isXwhenA = 0, B = 1, C = 1? - Why must the two-variable header across a 3-input K-map read
00, 01, 11, 10rather than00, 01, 10, 11? - Simplify the Boolean expression
Z = (A · B) + (A · NOT B)using either a 2-input K-map or Boolean algebra laws.
Common mix-up
It is easy to think: Write 00, 01, 10, 11 across the top of a 3-input K-map in normal binary order, or group 3 adjacent 1s into a single K-map block.
Instead, remember: Normal binary counting changes two bits at once between 01 and 10, breaking adjacency and giving invalid simplifications. Always use Gray code (00, 01, 11, 10), and only form rectangular or square groups whose sizes are powers of 2 (1, 2, 4, 8); a row of three 1s must be covered as two overlapping groups of 2.
Quick recap
- Complete truth tables list all
2^ninput combinations in binary counting order and use intermediate columns (P, Q, R) to trace multi-gate circuits or verbal problem specs accurately. - Boolean operator precedence evaluates
NOT, thenAND/NAND, thenOR/NOR/XOR/XNORunless parentheses specify another order. - Karnaugh maps use Gray-code labels (
00, 01, 11, 10), power-of-2 rectangular or square groups (including edge wraparound and overlaps), and keep only variables whose values stay constant across a group. - Boolean algebra laws (Identity, Null, Complement, Distributive, Absorption, De Morgan's) simplify expressions algebraically to the same minimal form.
Textbook reading
- Computer Science (Baumgarten, Ganea, Turland, 2025), A1 Computer fundamentals > A1.2 Data representation and computer logic > A1.2.4 Constructing and analysing truth tables, Book pp. 56–64 (PDF pp. 66–74).
- Read these pages to practice additional K-map exercises; this original explanation does not replace the textbook.
Sources and further learning
- IB Computer Science Guide (first assessment 2027), A1.2.4: Construct and analyse truth tables (Guide p. 29; PDF p. 35).
- Computer Science (Baumgarten, Ganea, Turland, 2025), A1.2.4 Constructing and analysing truth tables, Book pp. 56–64 (PDF pp. 66–74). All truth tables, problem scenarios, and K-map worked examples above are original.