IB Computer Science2027 syllabus
Level view
A1.2.4

Constructing and analysing truth tables

SL & HL35 min readLesson

In one sentence: Truth tables map every possible binary input combination (2^n rows) 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, then AND/NAND, then OR/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

TermSimple meaning
Input combinationOne specific assignment of 0s and 1s to every input variable, forming one row of a truth table.
Intermediate valueA temporary named signal (P, Q, R) representing a single gate's output inside a multi-gate circuit.
Operator precedenceThe 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 simplificationReducing 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

  • 1 input (A): 2^1 = 2 rows
  • 2 inputs (A, B): 2^2 = 4 rows
  • 3 inputs (A, B, C): 2^3 = 8 rows

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): Alternate 0, 1, 0, 1, ... every 1 row.
  • Middle column (B): Alternate 0, 0, 1, 1, 0, 0, 1, 1 every 2 rows.
  • Leftmost column (A): Alternate 0, 0, 0, 0, 1, 1, 1, 1 every 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): takes A and B to produce intermediate signal P = A ⊕ B
  • Gate 2 (OR): takes B and C to produce intermediate signal Q = B + C
  • Gate 3 (NAND): combines P and Q to produce intermediate signal R = NOT(P · Q)
  • Gate 4 (AND): combines R and input C to produce final output X = R · C

Evaluate one column at a time across all 8 rows:

ABCP = A ⊕ BQ = B + CR = NOT(P · Q)X = R · C
0000010
0010111
0101100
0111100
1001010
1011100
1100110
1110111

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:

  1. Identify input variables: Represent every binary condition as an input variable (A, B, C) and state clearly what 1 and 0 mean for each.
  2. List all 2^n input rows: Order the input combinations using binary counting.
  3. 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).
  4. Compute the final output column: Evaluate X for 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:

  1. NOT (highest priority; applies only to the variable or parenthesized group immediately under or after it)
  2. AND and NAND
  3. OR, NOR, XOR, and XNOR (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 AND term containing every input variable: keep variable V if its value in that row is 1, or NOT V (V̅) if its value is 0.
  • Connect all those AND terms with OR (+).

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: place 1 in the bottom-right cell.
  • A = 1, B = 0: place 1 in the bottom-left cell.
  • All other cells are 0.
A \ B01
000
111

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:

  1. Powers of 2 only: Every group must contain 1, 2, 4, 8 (or 16) adjacent 1s, never 3 or 6.
  2. Rectangular or square shapes only: No L-shapes or staggered zig-zags.
  3. No diagonals: Cells are adjacent only horizontally or vertically (including wrapping across opposite left/right edges, or top/bottom in 4-input maps).
  4. Make groups as large as possible: Larger groups eliminate more variables (1 cell eliminates 0 variables; 2 cells eliminate 1; 4 cells eliminate 2).
  5. Overlaps are permitted and helpful: Re-using an already covered 1 is encouraged whenever it creates a larger power-of-two group.
  6. Minimize the total number of groups: Cover all 1s using as few valid groups as possible; never add a redundant group whose 1s are all already covered.

Reading the simplified expression from groups

For each group:

  • Inspect every variable (A, B, C):
    • If its value stays 1 in every cell of the group, include V.
    • If its value stays 0 in every cell of the group, include NOT V (V̅).
    • If its value takes both 0 and 1 inside the group, discard that variable.
  • Join all retained variables inside one group with AND (·), and join separate groups with OR (+).

6. Algebraic Boolean simplification laws

You can also simplify Boolean expressions directly using algebra rules:

Law nameAND formOR form
IdentityA · 1 = AA + 0 = A
Null / DominanceA · 0 = 0A + 1 = 1
IdempotentA · A = AA + A = A
ComplementA · NOT A = 0A + NOT A = 1
Double negationNOT(NOT A) = AN/A
DistributiveA · (B + C) = A · B + A · CA + (B · C) = (A + B) · (A + C)
AbsorptionA · (A + B) = AA + (A · B) = A
De Morgan's lawsNOT(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).

  1. Define inputs and intermediates:
    • A = lockdown active (1) / not active (0); we need Q = NOT A.
    • B = gas detected (1 / 0); C = purge switch on (1 / 0); we need P = B + C.
    • Final output: X = Q · P = (NOT A) · (B + C).
  2. Truth table (2^3 = 8 rows):
ABCQ = NOT AP = B + CX = Q · P
000100
001111
010111
011111
100000
101010
110010
111010

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)

  1. Plot all five 1s onto the 3-input K-map (C down rows, AB in Gray order across columns):
C \ AB00 (NOT A·NOT B)01 (NOT A·B)11 (A·B)10 (A·NOT B)
01001
11011
  1. Group adjacent 1s as large as possible:
    • Group 1 (size 4, horizontal wraparound): Column AB = 00 (rows 0, 1) and column AB = 10 (rows 0, 1) wrap around the left and right edges to form a 2 × 2 square of 4 1s. Across {00, 10} and C ∈ {0, 1}, A flips between 0 and 1, C flips between 0 and 1, and B = 0 stays constant, giving the term NOT B.
    • Group 2 (size 2, overlapping horizontal pair): The single remaining 1 at (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), B flips between 1 and 0 while A = 1 and C = 1 stay constant, giving the term A · C.
  2. Simplified expression: Y = (NOT B) + (A · C).
  3. 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 law NOT 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

  1. How many rows are needed in a truth table with 4 binary inputs (A, B, C, D)?
  2. Without parentheses, which operation executes first in X = A + NOT B · C, and what is X when A = 0, B = 1, C = 1?
  3. Why must the two-variable header across a 3-input K-map read 00, 01, 11, 10 rather than 00, 01, 10, 11?
  4. 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^n input 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, then AND/NAND, then OR/NOR/XOR/XNOR unless 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.
Check your understanding5 questions · 8 marks · 12 min
Take the lesson check
Something not right?