Truth Tables, Explained
After reading this you can build the full truth table of any boolean expression, decide whether it is always true, never true, or somewhere in between, and read off its disjunctive and conjunctive normal forms.
What a truth table is
A truth table lists every possible assignment of true and false to the variables in a boolean expression, together with the value the expression takes for each assignment. If your expression uses n distinct variables, the table has 2^n rows, one for each combination.
Take the default expression (p | q) & ~r. It has three variables, so the table has 2^3 = 8 rows. The formula is true exactly when at least one of p and q is true and r is false. Out of the 8 rows, that happens in 3 of them: (p,q,r) = (T,F,F), (F,T,F), and (T,T,F). The other 5 rows come out false.
The operators the generator understands are & (and), | (or), ~ (not), ^ (exclusive or), -> (implies), and <-> (if and only if). Everything else is built from these.
The connectives and their tables
Each connective is defined by a small table. Memorize these six and you can evaluate any expression by hand.
| p | q | p & q | p | q | p ^ q | p -> q |
|---|---|---|---|---|---|
| T | T | T | T | F | T |
| T | F | F | T | T | F |
| F | T | F | T | T | T |
| F | F | F | F | F | T |
Negation flips a single value: ~T = F and ~F = T. The biconditional p <-> q is true when p and q agree, so it is true on the rows (T,T) and (F,F) and false on the other two. Notice one common surprise: p -> q is true whenever p is false. The row (F,T) gives T, and (F,F) also gives T. Implication only fails when a true premise leads to a false conclusion, the single row (T,F).
Read p -> q as "if p then q", not as cause and effect. It makes a claim only about the case where p holds. When p is false the promise is kept by default, which is why two of its four rows are true.
When to use it, and when not to
Truth tables are the right tool when you have a handful of variables and want a complete, mechanical answer. They prove equivalences, check whether an argument is valid, and expose hidden edge cases in conditions. With 3 variables you inspect 8 rows, with 4 you inspect 16, with 5 you inspect 32. That is still comfortable.
The cost is the 2^n growth. At 10 variables the table has 1024 rows, and at 20 variables it has 1048576. Past roughly 6 or 7 variables the table stops being something you read and becomes something a machine scans. For large formulas, algebraic simplification or a SAT solver is the practical route. Use the table to build intuition and to verify small claims exactly.
Tautology, contradiction, contingency
The generator classifies every expression into one of three kinds based on the output column.
- Tautology
- Every row is true. The expression holds under all assignments. Example:
p | ~pis true in both of its 2 rows. - Contradiction
- Every row is false. The expression can never hold. Example:
p & ~pis false in both rows. - Contingency
- At least one true row and at least one false row. The value depends on the inputs. The default
(p | q) & ~ris a contingency with 3 true rows out of 8.
To prove that two expressions are equivalent, form A <-> B and check that it is a tautology. To prove that an argument with premises H1, H2 and conclusion C is valid, check that (H1 & H2) -> C is a tautology.
Normal forms: DNF and CNF
Once you have the output column, two canonical formulas fall out directly.
The disjunctive normal form is an OR of AND-terms, one term per true row. In each term, a variable appears plain if it is true in that row and negated if it is false. So a formula in DNF is true exactly when one of its listed rows occurs.
The conjunctive normal form is an AND of OR-terms, one term per false row. In each clause the variable appears negated if it is true in that row and plain if it is false. The CNF rules out exactly the false rows. If a formula has 3 true rows out of 8, its DNF has 3 terms and its CNF has 5 clauses. The generator then simplifies these where common factors allow.
Pick the shorter form for your purpose. If most rows are true, the CNF is short because it lists the few false rows. If most rows are false, the DNF is short. For a balanced contingency the two are similar in size.
Worked example: a valid argument
Checking transitivity of implication
Enter (p -> q) & (q -> r) -> (p -> r) and press Calculate. This says: if p implies q and q implies r, then p implies r. It should be valid, so the table should be all true.
- List the 8 rows for
(p,q,r). - Compute the premise
(p -> q) & (q -> r)in each row. - Compute the conclusion
p -> r. - Combine them with the outer implication.
| p | q | r | premise | p -> r | whole |
|---|---|---|---|---|---|
| T | T | T | T | T | T |
| T | T | F | F | F | T |
| T | F | T | F | T | T |
| T | F | F | F | F | T |
| F | T | T | T | T | T |
| F | T | F | F | T | T |
| F | F | T | T | T | T |
| F | F | F | T | T | T |
The last column is true in all 8 rows, so the whole expression is a tautology and the argument is valid. Look at the second row: the premise is false (because q -> r fails when q=T, r=F), so the outer implication is true regardless of the conclusion. The tautology holds partly because the risky rows have false premises.
See how row counts and true rows behave
Common mistakes
The frequent error is misreading implication. Many people expect p -> q to be false whenever q is false, but the row (F,F) is true. Only (T,F) is false.
A second trap is operator precedence. The generator binds ~ tightest, then &, then |, then -> and <->. So ~p & q means (~p) & q, not ~(p & q). When in doubt, add parentheses. Compare p | q & r, which reads as p | (q & r), against the different formula (p | q) & r.
Exclusive or and the biconditional are opposites. p ^ q is true when the two disagree; p <-> q is true when they agree. In every row, p ^ q and p <-> q have opposite values. Do not use one where you mean the other.
Related tools
Boolean logic sits next to several other discrete-math topics on this site. For the algebra of collections and how union and intersection mirror OR and AND, see the Set Calculator. For number-theory work you can explore the Prime Number Tools, solve Linear Diophantine Equations, compute in any base with Base-N Arithmetic, or handle modular systems with the Congruence Solver (CRT).
Frequently asked questions
How many rows will my truth table have?
Count the distinct variables, call it n, and the table has 2^n rows. Three variables give 8 rows, four give 16, five give 32. Repeated uses of the same variable do not add rows.
What is the difference between DNF and CNF?
DNF is an OR of AND-terms built from the true rows, so it says "the formula is true in these cases". CNF is an AND of OR-clauses built from the false rows, so it says "the formula is not false in any of those cases". They describe the same function from opposite sides.
Why is my implication true when I expected false?
Implication p -> q is false only on the single row where p is true and q is false. In the other three rows it is true, including both rows where p is false.
How do I prove two expressions are equivalent?
Combine them as A <-> B and generate the table. If the result is a tautology (every row true), the two are equivalent for all inputs.
Can I use words like AND and OR instead of symbols?
Use the symbols the generator lists: &, |, ~, ^, ->, <->. They map one to one onto the connectives in the tables above.