On this concept: Formula

Not sure which lesson to do first? Find your level and get a plan →

CS Thinking · Computational Thinking · Grade 9-12

Truth Tables

A truth table lists every combination of boolean inputs alongside the output a logical expression produces for each.

2n rows for n boolean variables

Quick Answer

A truth table lists every combination of boolean inputs alongside the output a logical expression produces for each. You use it when you need certainty about every case: to describe exactly what a condition or logic circuit does, to prove that two expressions are equivalent, or to find the one input combination where a rule misbehaves. With n inputs there are 2n rows, so the method is complete but grows quickly: 3 inputs need 8 rows, and 10 inputs need 1,024.

Why This Matters

A truth table turns 'I think these two conditions do the same thing' into a check you can finish. Engineers use one to specify a logic gate before building it, and programmers use one to simplify a tangled if-statement safely. Without it, people test the two or three cases they happen to think of, and the bug waits in a row they never wrote down.

Intuitive Explanation

Take the rule 'free shipping if the customer is a member OR the order is over $50'. Two inputs, each true or false, give four situations: member with a large order, member with a small order, non-member with a large order, non-member with a small order. Put each on its own row, compute member OR large for that row, and you have the truth table: three rows say true, and only the non-member with a small order pays for shipping. The table is the rule's complete behaviour, with nothing left to argue about.

Rows double with each new input, because every existing row splits into one where the new input is true and one where it is false: 1 input gives 2 rows, 2 give 4, 3 give 8, and n give 2n. A reliable way to list them is to count in binary with F for 0 and T for 1: FFF, FFT, FTF, FTT, and so on up to TTT. Counting guarantees that no row is skipped or repeated.

The payoff is proof. Two expressions are equivalent exactly when their output columns match in every row; De Morgan's law ¬(A∧B)≡¬A∨¬B passes in all four rows. Compare ¬(A∧B) with ¬A∧¬B: they agree when both inputs are true and when both are false, but split when exactly one is true. Testing only those two easy rows looks like a truth table but is not one, and it would wrongly call the expressions equal. And if a question gives one specific set of values, you need a single evaluation, not a table.

Think of it like this. A truth table is like trying every setting of a lock whose wheels each have only two positions. Three wheels give 8 settings, few enough to try them all and know for certain which ones open it. The picture also shows why the method stops being practical: 30 wheels would mean more than a billion settings.

Core idea. Truth tables exhaustively verify logical expressions and can reveal equivalences between different expressions.


When to Use

Build a truth table when a question says every combination, all cases, equivalent or always about a logical expression, or when a logic gate or circuit must be specified completely. It is also the safe way to check a simplified condition before rewriting code. If you are given one set of input values, just evaluate the expression with logical operators. With many inputs (6 inputs already need 64 rows), switch to algebraic laws such as De Morgan's, or let a program generate the table.

Tip. Ask: Must the answer cover every combination of true/false inputs, one row each, rather than a single case?

How to Recognize It

Check whether the question demands certainty about all cases, which only a full listing of the inputs can give.

  1. Does the question ask about all possible inputs, such as proving two conditions always agree?

    Yes needs a truth table, since only checking every row proves it. If you need the result for just one set of values, evaluate it directly with Logical Operators.

  2. Are there few enough inputs that all 2n rows can really be written out?

    Yes, with up to about 4 inputs (16 rows), a table is practical. With 20 inputs it would need over a million rows, so you would reason with the laws of Boolean Logic instead.

  3. Is the output a fixed function of the inputs, with no order of steps or memory involved?

    Yes suits a truth table. If the result depends on steps happening in order, such as a loop counting up, it is an Algorithm to trace, not a table.

  4. Are you hunting for the one input combination where a rule gives the wrong result?

    Yes is a strong use of a truth table, because every row sits side by side. If you already know the failing input and need to change the code, that is Debugging.

Truth Tables vs Logical Operators vs Boolean Logic vs Nested Conditionals

Truth tables, logical operators and Boolean logic share symbols, and nested conditionals also handle combinations of conditions. Ask whether you need every case laid out at once, one case worked out, a general law, or code that acts on each case.

Truth Tables

Meaning
A truth table records the output of a logical expression for each of the 2n ways to set its n inputs.
Key test
Every input combination appears as its own row.
Formula
2n rows for n inputs
Example
A XOR B: F,F→F; F,T→T; T,F→T; T,T→F, so true appears in exactly two rows.

Logical Operators

Meaning
Logical operators such as AND, OR and NOT combine or flip true/false values to produce one result.
Key test
One set of input values, one result.
Formula
A∧B
Example
With A true and B false, A AND B gives false and A OR B gives true.

Boolean Logic

Meaning
Boolean logic is the algebra of true and false, with laws that let you rewrite expressions without listing cases.
Key test
You apply a general law instead of checking row by row.
Formula
¬(A∨B)=¬A∧¬B
Example
Simplifying A AND (A OR B) to just A with the absorption law.

Nested Conditionals

Meaning
Nested conditionals are if statements placed inside other if statements, so code can act differently for each combination of conditions.
Key test
It is code that does something in each case, not a table of outputs.
Example
if raining: (if cold: wear a coat, else: take an umbrella), else: wear a T-shirt.

Formula & Notation

2n rows for n boolean variables
A truth table for a boolean function f:{T,F}n→{T,F} enumerates all 2n input combinations and the corresponding output. Two expressions are logically equivalent iff their truth tables have identical output columns.

How to read it: ⊤ (true) and ⊥ (false) are the two truth values. Common operators: ∧ (AND), ∨ (OR), ¬ (NOT), → (implies), ↔ (iff).

Worked Examples

Example 1 — Build a three-input table

Easy

Build the truth table for (A∨B)∧¬C, where A = 'customer is a member', B = 'order is over $50' and C = 'address is overseas'. In how many rows is the expression true?
Show the steps and the answer
  1. Count the rows: 3 inputs give 23=8 rows.

    Writing the count first means a missing row shows up straight away.

  2. List (A, B, C) by counting in binary from FFF to TTT, and add a column for A∨B: it is false only in rows FFF and FFT.

    OR is false only when both of its inputs are false, so only the two rows with A and B both false get F.

  3. Add a column for ¬C: true in the four rows where C is F (FFF, FTF, TFF, TTF).

    NOT flips the C column, so the helper column is ready for the final AND.

  4. AND the two helper columns: FFF gives F∧T=F; FTF, TFF and TTF give T∧T=T; the four rows with C true give F.

    AND is true only where both helper columns are true, which happens in three rows.

Answer: 8 rows; the expression is true in 3 of them: (A, B, C) = (F, T, F), (T, F, F), (T, T, F).

Takeaway: Count 2n rows first, then build helper columns one operator at a time so each final output is a simple lookup.

Example 2 — Is the rewrite safe?

Standard

A school-day alarm uses the condition not (isWeekend or isHoliday). A programmer wants to rewrite it as not isWeekend or not isHoliday. Use a truth table to decide whether the rewrite is safe.
Show the steps and the answer
  1. Set up 4 rows for W (weekend) and H (holiday): TT, TF, FT, FF.

    Two inputs give 22=4 rows, and an equivalence claim must hold in all of them.

  2. Original ¬(W∨H): F, F, F, T.

    W∨H is true in the first three rows, so its negation is true only on a day that is neither a weekend nor a holiday.

  3. Rewrite ¬W∨¬H: F, T, T, T.

    An OR of the two negations is false only when both negations are false, which happens only in row TT.

  4. Compare the columns: they differ in rows TF and FT.

    On an ordinary Saturday (W true, H false) the original stays silent but the rewrite rings. Rows TT and FF agree, so testing only those two would have missed the bug.

  5. Try ¬W∧¬H: F, F, F, T, matching the original in all 4 rows.

    This is De Morgan's law: the NOT of an OR becomes the AND of the NOTs.

Answer: The rewrite is not safe: it differs from the original in 2 of the 4 rows. The safe version is not isWeekend and not isHoliday.

Takeaway: Two expressions are equivalent only if every row matches; agreement on the all-true and all-false rows proves nothing.

Example 3 — Find the mistake: half a table

Application

Ravi builds a truth table for A∧(B∨C) using four rows (A, B, C): TTT, TFF, FTF, FFT. Only TTT gives true, so he writes: "The expression is true only when all three inputs are true." Find the mistake and correct it.
Show the steps and the answer
  1. Count the rows needed: 23=8. Ravi listed 4.

    Each of the 3 inputs doubles the number of cases, so his table is missing half the combinations.

  2. Find the missing rows by counting FFF to TTT and crossing off his four: FFF, FTT, TFT, TTF.

    Binary counting lists every combination once, so whatever is not crossed off was skipped.

  3. Evaluate them: TTF gives T∧(T∨F)=T; TFT gives T∧(F∨T)=T; FTT and FFF give F because A is false.

    Two of the skipped rows are true, so they overturn Ravi's conclusion.

  4. Read the full output column: true for TTT, TTF and TFT.

    The expression needs A true and at least one of B, C true; it does not need all three.

Answer: The full table has 8 rows, and the expression is true in 3: (A, B, C) = (T, T, T), (T, T, F), (T, F, T). It is true whenever A is true and B or C is true.

Takeaway: Write the row count 2n before filling in a table; a conclusion from a partial table can be wrong in exactly the rows you skipped.

Where You'll See It

  • Checking every case of a 'free shipping' rule

    Free shipping applies if a member OR the order is over $50. A truth table lists all four member/over-$50 combinations so you can confirm the rule does the right thing in every situation, not just the one you tested.

  • Designing a logic-gate circuit

    Hardware engineers write a truth table for an AND or XOR gate listing every input combination and its output — the table fully specifies the chip's behavior before any wires are drawn.

  • Proving two if-conditions are the same

    To simplify a messy condition, you build truth tables for the old and new versions and compare every row — if all outputs match, the expressions are equivalent and the simpler one is safe to use.

Common Mistakes

  1. The slip: You can confirm two expressions are equivalent by checking a couple of input combinations.

    Why it's tempting: If the first few rows agree, the expressions seem clearly identical.

    Instead: Equivalence requires that ALL 2^n rows match. A difference can hide in a single untested combination, so you must compare every row.

  2. The slip: A truth table for n variables has n rows (or some smaller, convenient number).

    Why it's tempting: Listing one row per variable feels natural and tidy.

    Instead: Each variable doubles the cases, so a complete truth table has 2^n rows for n variables — 2 variables give 4 rows, 3 give 8. Missing rows means missing input combinations.

  3. The slip: Working A∨B∧C left to right, as (A∨B)∧C.

    Why it's tempting: Reading left to right is a habit, and with no brackets there seems to be no reason to group any other way.

    Instead: AND is done before OR (and NOT before both), so the expression means A∨(B∧C). In the row A = T, B = F, C = F the two readings split: T∨(F∧F)=T, but (T∨F)∧F=F.


Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. How many rows does a truth table need for 3 inputs? For 5 inputs?

    Hint: Each extra input doubles the number of combinations.

  2. Build the truth table for A OR NOT B, with rows in the order TT, TF, FT, FF for (A, B). Which row is false?

    Hint: Write a NOT B column first, then OR it with A.

  3. Use a truth table to check whether NOT (A AND B) is equivalent to (NOT A) OR (NOT B).

    Hint: Fill both output columns for all four rows, then compare.

  4. In the 8-row truth table for (A AND B) OR C, how many rows are true?

    Hint: Count the rows with C true, then add rows where C is false but A AND B is true.

  5. A door unlocks when (card AND pin) OR master. Question 1: does it unlock for card = T, pin = F, master = F? Question 2: in which situations does it unlock? Which question needs a truth table?

    Hint: One question asks about a single case. The other asks about every case.

  6. A student checks only rows TT and TF, sees that A OR B and A give the same output, and says: 'They are equivalent.' Are they?

    Hint: Check the rows the student skipped.

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Frequently Asked Questions

Why list the rows in a fixed order?

Because a fixed order makes missing or repeated rows easy to spot. The standard method is to count in binary: with 3 inputs, rows 000 to 111 are the numbers 0 to 7, so every combination appears exactly once. The first input column then reads FFFFTTTT, the second FFTTFFTT and the third FTFTFTFT. Two tables built this way can be compared row by row.

How does a truth table help design a circuit?

Each row says what the output wire must be for one setting of the input wires. From the rows where the output is 1, you can write an expression directly: one AND term per row, joined by OR. For XOR that gives (NOT A AND B) OR (A AND NOT B), which can be built from gates and then simplified. This method, called sum of products, works for any table.

Why is 'if A then B' true when A is false?

The expression A→BA \to B is false in only one row: A true and B false. Think of it as a promise: 'if it rains, I bring an umbrella'. On a dry day you have not broken the promise, whatever you carry, so logic counts those rows as true. Students often expect false when A is false, but a promise that was never tested counts as kept.

Learning Path

Truth Tables

You are here

Next →

Nothing after this yet
You need Boolean Logic (the values true and false) and Logical Operators (AND, OR, NOT and their precedence) first. A truth table adds a complete row-by-row record of an expression over all 2n input combinations, which makes equivalence provable. With it you can design and simplify circuits built from logic gates, rewrite tangled if-conditions with confidence, and test a program's branches against every combination of its boolean inputs.

See Also