Truth Table Generator
Type a logical expression to get its complete truth table, with a column for every sub-expression. The tool also tells you whether the expression is a tautology, a contradiction or a contingency, checks two expressions for equivalence and writes out the canonical DNF and CNF.
Expression
The buttons insert at the cursor of the box you used last. You
can also type not, and, or, xor,
->, <-> or ! & | – the full list is in the
table at the bottom of the tool.
Everything is computed in your browser – nothing you type is sent to a server.
Truth table
The table appears here as soon as the expression is valid.
Normal forms
The normal forms appear here as soon as the expression is valid.
Operators and precedence
| Rank | Operator | Symbol | You can also type |
|---|---|---|---|
| 1 | NOT negation | ¬ | ! ~ ∼ not |
| 2 | AND conjunction | ∧ | & && · * and |
| 3 | XOR exclusive or | ⊕ | ^ xor |
| 4 | OR disjunction | ∨ | | || + or |
| 5 | IMPLIES conditional | → | -> => ⇒ ⊃ implies |
| 6 | IFF biconditional | ↔ | <-> <=> ⇔ ≡ iff |
| – | Constants true, false | T, F | true false 1 0 ⊤ ⊥ |
Rank 1 is applied first, rank 6 last.
→ groups to the right, so p → q → r means
p → (q → r); the other two-sided operators group to the left. Words are not
case-sensitive, variable names are: a variable is a letter followed by letters, digits or
underscores (p, x1, is_raining). There is no implicit
AND – write p ∧ q, not p q.
How to use the truth table generator
- Type an expression or pick an example. The buttons insert ¬ ∧ ∨ → ↔ ⊕, parentheses,
T and F at the cursor; keyboard spellings such as
not,&,|and->work too. - Read the table: one column per variable, one per compound sub-expression, and the highlighted last column for the whole expression.
- Check the classification and the number of true rows.
- To compare two formulas, fill in the second box; rows where they differ are marked.
- Set T/F or 1/0, the row order and the variable order, then copy the table as text, Markdown, LaTeX or CSV.
How it works
A truth table lists every combination of truth values of the variables and gives the
value of the expression for each one. Each variable doubles the number of combinations,
so n variables need 2n rows: 4 for two variables, 8
for three and 256 for eight, the limit of this tool.
The generator builds an expression tree from your text using the precedence rules, then evaluates it for every row from the innermost parts outwards; the intermediate results are the sub-expression columns. To read a row, find the values of the variables on the left and follow it to the last column.
The six connectives are defined by these tables:
| p | ¬p |
|---|---|
| T | F |
| F | T |
| p | q | p ∧ q |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | F |
| p | q | p ∨ q |
|---|---|---|
| T | T | T |
| T | F | T |
| F | T | T |
| F | F | F |
| p | q | p → q |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | T |
| F | F | T |
| p | q | p ↔ q |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | T |
| p | q | p ⊕ q |
|---|---|---|
| T | T | F |
| T | F | T |
| F | T | T |
| F | F | F |
Why "false implies anything" is true
p → q is false in exactly one case: p true and
q false. Take the promise "if it rains, I will bring an umbrella". You
break it only on a rainy day without the umbrella. On a dry day the promise was never
tested, so it was not broken – and in two-valued logic a statement that is not false is
true. That is why both rows with a false p contain T, and why
p → q has the same table as ¬p ∨ q.
Precedence and parentheses
Without parentheses the tool applies ¬ first, then ∧, ⊕, ∨, → and finally ↔. So
p ∨ q ∧ r means p ∨ (q ∧ r), true in 5 of 8 rows, while
(p ∨ q) ∧ r is true in only 3. Implication groups to the right:
p → q → r means p → (q → r), true in 7 of 8 rows. Textbooks
differ on these conventions, so write parentheses whenever a formula mixes operators;
the "Read as" line shows how the tool grouped your input.
Examples
Example 1 – implication. p → q gives T, F, T, T for the
rows TT, TF, FT, FF: a contingency, true in 3 of 4 rows. Minterms Σm(0, 1, 3), maxterm
ΠM(2), canonical CNF (¬p ∨ q).
Example 2 – De Morgan's law. Enter ¬(p ∧ q) and, as the
second expression, ¬p ∨ ¬q. Both columns read F, T, T, T, so the result is
"Equivalent".
Example 3 – a tautology. The hypothetical syllogism
(p → q) ∧ (q → r) → (p → r) is true in all 8 rows.
Example 4 – not equivalent. p → q and its converse
q → p differ in 2 of 4 rows; the counterexample shown is p = T, q = F. The
contrapositive ¬q → ¬p, however, is equivalent to p → q.
Tautology, contradiction and contingency
A tautology is true in every row, like p ∨ ¬p. A
contradiction is false in every row, like p ∧ ¬p. Everything
else is a contingency: true for some assignments, false for others. A
formula is satisfiable when at least one row is true, so only contradictions are
unsatisfiable.
Logical equivalence and De Morgan's laws
Two expressions are logically equivalent when their columns agree in every row – that
is, when joining them with ↔ gives a tautology. De Morgan's laws are the best-known
pair: ¬(p ∧ q) is equivalent to ¬p ∨ ¬q, and
¬(p ∨ q) to ¬p ∧ ¬q. Negating an "and" gives an "or" of the
negations, and vice versa. If the formulas use different variables, the tool compares
them over all variables that occur in either.
DNF, CNF, minterms and maxterms
Every truth table can be turned back into a formula. For the canonical DNF (disjunctive normal form) take each true row, write an AND of all variables – negated where the variable is F – and join these terms with OR. Each term is a minterm: true in exactly one row. For the canonical CNF (conjunctive normal form) take each false row, write an OR of all variables – negated where the variable is T – and join the clauses with AND. Each clause is a maxterm: false in exactly one row.
Rows are numbered by reading the variables as a binary number (T = 1, F = 0), the
first variable being the most significant bit. a and (b or not c) is true
in rows 100, 110 and 111, so it is Σm(4, 6, 7). A tautology has no false rows, so its
CNF is T; a contradiction has no true rows, so its DNF is F.
Canonical forms are correct but rarely the shortest.
Frequently asked questions
Why does my course use different symbols?
Notation depends on the field. Logic and discrete mathematics write ∧, ∨, ¬ and →;
programming languages use &, | and !; digital
electronics writes AND as · and OR as +; many philosophy texts
use ⊃ for implication, ≡ for the biconditional and ~ for negation. The tool accepts all
of them and displays the result with ¬ ∧ ⊕ ∨ → ↔.
What is the difference between OR and XOR?
p ∨ q is inclusive: true when at least one side is true, including both.
p ⊕ q is exclusive: true when exactly one side is true. The two tables
differ only in the row where both are true.
How many variables can I use?
Up to 8, which gives 256 rows. A ninth variable would need 512, so the tool shows a message instead of a table.
Why is "p q" an error, and why is T not a variable?
There is no implicit AND: two expressions next to each other need an operator between
them, so write p ∧ q. Capital T and F are
reserved for the constants true and false; names are case-sensitive, so lower-case
t and f are ordinary variables. Note also that ^
means XOR here, not AND.
Is my expression sent anywhere?
No. Everything runs in JavaScript in your browser and nothing is uploaded. Your last expressions and settings are kept only in this browser's local storage, so they are still there on your next visit.
Related tools
- Two's Complement Calculator – signed binary numbers, binary addition and subtraction.
- Subnet Calculator – network, broadcast address and host range of an IPv4 subnet.
- Regex Tester – test regular expressions live and inspect the matches.
- Pathfinding Visualizer – watch A*, Dijkstra, BFS and DFS search a grid.
- Neural Network Playground – watch a small neural network learn to separate points.