Truth Tables

Learn to build a truth table for any compound expression step by step and use it to find tautologies, contradictions and equivalent expressions.

Intermediate25 minLesson

Definition

A truth table lists every possible combination of truth values of the variables in an expression and shows the value of the whole expression in each row.
How many rows? Each variable can be T or F, so every new variable doubles the number of rows:
rows=2n(n=number of variables)\text{rows} = 2^n \quad (n = \text{number of variables})
So 2 variables need 22=42^2 = 4 rows and 3 variables need 23=82^3 = 8 rows.
Building a table in 4 steps:
  1. 1.Count the variables and write 2n2^n empty rows.
  2. 2.Fill the variable columns in a fixed order: the first column is half T, then half F; each next column switches twice as often; the last column alternates T, F, T, F.
  3. 3.Add a helper column for every part of the expression, innermost part first (a NOT on a single variable, then the brackets).
  4. 4.Combine the helper columns into the final column.
Example: P∧¬QP \land \neg Q
PPQQ¬Q\neg QP∧¬QP \land \neg Q
TTFF
TFTT
FTFF
FFTF
The final column tells you everything: this expression is true in exactly one row, when PP is true and QQ is false.
Reading the final column:
  • All T: the expression is a tautology (always true).
  • All F: it is a contradiction (always false).
  • Two expressions with the same final column in every row are logically equivalent.

Try it now

How many rows does a truth table with 3 variables have?

Worked Examples

Build the truth table for P∨¬QP \lor \neg Q.

1

Count the rows

There are 2 variables, PP and QQ, so we need 22=42^2 = 4 rows

2

Fill the variable columns

PP: T, T, F, F (half T, half F). QQ: T, F, T, F (alternating) → All 4 combinations appear once

3

Add the helper column ¬Q\neg Q

Flip every value of QQ: T, F, T, F becomes F, T, F, T → ¬Q\neg Q: F, T, F, T

4

Combine with OR

Row by row: T OR F = T, T OR T = T, F OR F = F, F OR T = T → P∨¬QP \lor \neg Q: T, T, F, T

Common Mistakes

Writing too few rows, for example 6 rows for 3 variables

Why it's wrong: The number of rows is not 2×n2 \times n. Each variable doubles the number of combinations, so 3 variables give 2×2×2=82 \times 2 \times 2 = 8 rows.

Correct: Always use 2n2^n rows: 4 for 2 variables, 8 for 3 variables, 16 for 4 variables.

Filling the variable columns in a random order

Why it's wrong: Without a system it is easy to write the same combination twice and miss another one. The table then gives a wrong verdict.

Correct: Use the fixed pattern: first column in blocks of half the rows, each next column in blocks half as long, last column alternating T, F.

Treating ¬P∧Q\neg P \land Q as if it were ¬(P∧Q)\neg(P \land Q)

Why it's wrong: Without brackets, NOT applies only to the variable right after it. The bracketed version flips the result of the whole AND.

Correct: Make a helper column for exactly what NOT touches: ¬P\neg P alone, or P∧QP \land Q first and then its negation.

Calling two expressions equivalent after checking only a few rows

Why it's wrong: Two expressions can agree on several rows and still differ in one. ¬(P∧Q)\neg(P \land Q) and ¬P∧¬Q\neg P \land \neg Q agree in rows 1 and 4 but not in rows 2 and 3.

Correct: Compare the final columns in every single row. Equivalent means identical in all 2n2^n rows.

Interactive Visual

Truth Table

ExpressionP ∧ Q ∨ ¬R
PQRP ∧ Q¬RP ∧ Q ∨ ¬R
TTTTFT
TTFTTT
TFTFFF
TFFFTT
FTTFFF
FTFFTT
FFTFFF
FFFFTT

T= TrueF= False

Truth Table

ExpressionP ∨ ¬Q
PQP ∨ ¬Q
TT
TF
FT
FF

T= TrueF= False

Interactive Sandbox

Expression Calculator

Try these:

History

No calculations yet

Practice Problems

18 problems
Problem 1 of 18
Easy

How many rows does a truth table with 3 variables have?

Why It Matters

A truth table is the most reliable way to check a logical statement, because it leaves no case out:
  • Programming: before shipping a condition like (member OR coupon) AND NOT blocked, testers check every combination of inputs
  • Electronics: engineers use truth tables to design circuits and to replace a complicated circuit with a simpler, cheaper one that does the same job
  • Security and alarms: an alarm with 4 sensors has 24=162^4 = 16 possible states, and every one of them must behave correctly
  • Arguments and debates: a truth table shows whether two sentences really say the same thing or only sound alike
  • Puzzles and games: logic puzzles are solved by ruling out rows that cannot be true
You already know how AND, OR and NOT work on their own. Truth tables let you combine them into any expression and still be sure of the answer.

Real World Applications

Alarm Systems

Security engineers list every state of the sensors to make sure the alarm reacts correctly in each one.

Example:

An alarm with 3 door sensors has 23=82^3 = 8 states, from all doors closed to all doors open.

1Try It Yourself

A house alarm has 4 sensors, and each one is either on (T) or off (F). The alarm rings if at least one sensor is on (OR).

How many rows does the truth table have, and in how many of them does the alarm ring?

Step 1: Write the mathematical expression

Write the number of rows as a power of 2:

Testing Software

Programmers test a condition with every combination of inputs, which is exactly a truth table.

Example:

A login rule (correct password AND NOT locked) needs 22=42^2 = 4 test cases to be fully checked.

2Try It Yourself

An online shop gives a discount if (M∨C)∧¬B(M \lor C) \land \neg B, where MM = is a member, CC = has a coupon, BB = account is blocked.

In how many of the input combinations does the customer get the discount?

Step 1: Write the mathematical expression

Write the number of test cases as a power of 2:

Simplifying Circuits

If two circuits have the same truth table, engineers can use the one with fewer or cheaper parts.

Example:

De Morgan's laws let a designer swap a NOT-AND for an OR of two NOTs without changing what the circuit does.

3Try It Yourself

Circuit A computes ¬(P∨Q)\neg(P \lor Q). Circuit B computes ¬P∧¬Q\neg P \land \neg Q.

Do the two circuits always give the same output?

Step 1: Write the mathematical expression

Write the number of rows as a power of 2:

Key Takeaways

  • 1A truth table lists every combination of truth values and the value of the expression in each row
  • 2With nn variables the table has 2n2^n rows: 4 for 2 variables, 8 for 3 variables
  • 3Fill the variable columns in a fixed order: blocks of half the rows first, last column alternating T, F
  • 4Use helper columns for each part of the expression, innermost part first
  • 5All T in the final column means a tautology, all F means a contradiction
  • 6Two expressions are equivalent when their final columns match in every row

Frequently Asked Questions

Each existing row can be continued with the new variable being T or being F. So every row splits into two: 2 rows become 4, 4 become 8, and so on, which gives 2n2^n.
Each existing row can be continued with the new variable being T or being F. So every row splits into two: 2 rows become 4, 4 become 8, and so on, which gives 2n2^n.
Any order is correct as long as every combination appears exactly once. The standard order (starting with all T) makes it easy to check and to compare tables. Some books start with F instead; the rows are the same, only listed the other way round. The interactive tables in this lesson use the standard order.
It is called a contingency: its value depends on the inputs. Most everyday expressions, like P∧QP \land Q, are contingencies.
They are not required, but they prevent most mistakes. With practice you can combine small steps in your head, but for 3 variables or brackets inside brackets, helper columns are the safest way.

Glossary

Truth table
A table that shows the value of an expression for every combination of its variables
Compound expression
An expression built from variables and operators, such as (P∧Q)∨¬R(P \land Q) \lor \neg R
Helper column
An extra column for one part of an expression, used to build the final column step by step
Tautology
An expression that is true in every row, such as P∨¬PP \lor \neg P
Contradiction
An expression that is false in every row, such as P∧¬PP \land \neg P
Logically equivalent
Two expressions with the same value in every row, written with ≡\equiv

Formula Card

Number of rows

rows=2n\text{rows} = 2^n

$n$ is the number of variables: $2^2 = 4$, $2^3 = 8$, $2^4 = 16$

Tautology

P∨¬PP \lor \neg P

Always true: the final column is all T

Contradiction

P∧¬PP \land \neg P

Always false: the final column is all F

De Morgan's laws

¬(P∧Q)≡¬P∨¬Q,¬(P∨Q)≡¬P∧¬Q\neg(P \land Q) \equiv \neg P \lor \neg Q, \quad \neg(P \lor Q) \equiv \neg P \land \neg Q

Two equivalences you can prove with a truth table

More in This Topic