Propositional logic · Free · No sign-up
Online Truth Table Generator
Type a formula, hit Generate table and get its complete truth table: one column for every atom and one for every subformula, from the inside out, up to the main connective. It also tells you whether the formula is a tautology, a contradiction or a contingency.
Truth table generator
Use the buttons if you can't type the symbolsWhat is a truth table?
A truth table is a table that records the truth value (true or false) of a propositional logic formula for every possible combination of its variables. If the formula has n distinct variables, there are 2ⁿ combinations, that is, 2ⁿ rows.
The idea is to build it up column by column: first one column for each atom (each standalone variable, such as P, Q, R), and then a new column for each subformula, starting with the innermost ones and combining them until we reach the main connective, which is the one that determines the value of the whole formula.
The last column already tells us what kind of formula we have: a tautology (always true), a contradiction (always false) or a contingency (true in some cases and false in others).
Truth tables of the basic connectives
These are the "atomic" tables you will use to fill in any column. Every formula, however complex, comes down to applying these rules over and over. (T = true, F = false).
Negation · ¬A
Flips the value
| A | ¬A |
|---|---|
| T | F |
| F | T |
Conjunction (AND) · A ∧ B
T only if both are T
| A | B | A∧B |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | F |
Disjunction (OR) · A ∨ B
F only if both are F
| A | B | A∨B |
|---|---|---|
| T | T | T |
| T | F | T |
| F | T | T |
| F | F | F |
Conditional (Implication) · A → B
F only when T → F
| A | B | A→B |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | T |
| F | F | T |
Biconditional (If and only if) · A ↔ B
T if both have the same value
| A | B | A↔B |
|---|---|---|
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | T |
Exclusive disjunction (XOR) · A ⊕ B
T if they have different values
| A | B | A⊕B |
|---|---|---|
| T | T | F |
| T | F | T |
| F | T | T |
| F | F | F |
NAND · A | B
The negation of ∧
| A | B | A|B |
|---|---|---|
| T | T | F |
| T | F | T |
| F | T | T |
| F | F | T |
NOR · A ↓ B
The negation of ∨
| A | B | A↓B |
|---|---|---|
| T | T | F |
| T | F | F |
| F | T | F |
| F | F | T |
How to build a truth table step by step
The method is always the same, no matter how many connectives the formula has:
Step 1 · Identify the variables
Find the distinct atoms (for example P, Q, R). Each one will be a column on the left-hand side of the table.
Step 2 · Work out the number of rows
With n variables there are 2ⁿ rows. With 2 variables → 4 rows; with 3 → 8; with 4 → 16, and so on.
Step 3 · Fill in the combinations
Write out every combination of T and F. The most common convention (and the one this generator uses) is: the leftmost variable changes most slowly and we start with all T at the top. That way you never miss a combination.
Step 4 · We add one column per subformula
The whole formula is not evaluated in one go: we assemble it in pieces, and each piece (each subformula) gets its own column, which we work out from the columns we already have to its left. To know what order those pieces go in, we follow the same idea as the order of operations in arithmetic.
2 + 3 × 4 multiplication is "stronger" than addition, so we do 3 × 4 = 12 first and then 2 + 12 = 14, never the other way round. The same happens in logic: some connectives are stronger than others, so we form the small groups first and combine them until the end.
Which one comes first? The parentheses decide; and if there are none, the strength of each connective.
1) If the formula has parentheses written in, the parentheses rule. What is inside gets resolved first and we work outwards. In ¬(P ∨ (Q ∧ R)) the pieces (and therefore the columns) would come out in this order:
Q ∧ R→ the innermost parentheses; the first piece.P ∨ (Q ∧ R)→ we join that group with thePnext to it.¬(P ∨ (Q ∧ R))→ the complete formula, applying the negation to everything.
2) If the formula has no parentheses, we place them mentally ourselves according to the strength of each connective: the strongest one binds first with whatever is next to it and forms the smallest group. From strongest to weakest it goes like this:
| Strength | Connective |
|---|---|
| + strongest (binds first) | ¬ (negation) |
| ∧ (and) · NAND | |
| ⊕ (xor) | |
| ∨ (or) · NOR | |
| → (implies) | |
| − weakest (binds last) | ↔ (if and only if) |
For example, in ¬P ∨ Q ∧ R we haven't written a single parenthesis, but the strength of the connectives already tells us how everything binds. Since ∧ is stronger than ∨, the first thing to join up is Q ∧ R; the negation sticks to its variable, so we have ¬P; and the last one to join is the ∨, which puts ¬P together with the group Q ∧ R. So, without having written a single parenthesis, we already know what to resolve first: we start with Q ∧ R, then ¬P, and finally we join it all with the ∨. That outermost ∨ is the main connective.
Step 5 · We evaluate column by column
We fill in each column using the tables of the basic connectives above, until we reach the main connective (the last column).
Step 6 · We read the result
We look at the last column: if it is all T, it is a tautology; if it is all F, a contradiction; and if there are both, a contingency (satisfiable but not valid).
Worked example step by step
Let's build the truth table of (P → Q) ⊕ R ∧ ¬Q following the six steps. Notice that this formula mixes several of the things we explained above.
Step 1 · We identify the variables. We look for the distinct letters that appear in the formula: P, Q and R. That's 3 variables, and each one will be a column on the left of the table.
Step 2 · We work out the number of rows. With 3 variables there are 2³ = 8 possible combinations of T and F, so the table will have 8 rows.
Step 3 · We fill in the combinations. We write out the 8 combinations of T and F starting with all T at the top, so that each column changes more slowly than the one to its right. Done that way, they look like this:
| P | Q | R |
|---|---|---|
| T | T | T |
| T | T | F |
| T | F | T |
| T | F | F |
| F | T | T |
| F | T | F |
| F | F | T |
| F | F | F |
Step 4 · We decide the columns (from the inside out). This is where we apply precedence. The piece (P → Q) already comes grouped by its parentheses. The piece R ∧ ¬Q has no parentheses, but the strength of the connectives tells us how it groups: since ¬ is the strongest, first we have ¬Q; and since ∧ is stronger than ⊕, the R joins with ¬Q to form R ∧ ¬Q. The last one to join is the ⊕, which combines the two blocks: that is the main connective. In other words, even though it is written without those parentheses, the formula behaves like (P → Q) ⊕ (R ∧ ¬Q). So the columns, from the innermost to the main one, are:
P → Q→ the piece on the left, already closed off by its parentheses.¬Q→ the negation ofQ.R ∧ ¬Q→ we joinRwith the¬Qcolumn.(P → Q) ⊕ (R ∧ ¬Q)→ the complete formula: it joins columns 1 and 3 with the ⊕.
Step 5 · We evaluate column by column. We fill in each new column using the tables of the basic connectives and looking at the columns we already have on the left:
P → Q: it is F only whenP = TandQ = F; in every other case, T.¬Q: we flip theQcolumn (where there was T we put F and vice versa).R ∧ ¬Q: it is T only whenR = Tand¬Q = Tat the same time.(P → Q) ⊕ (R ∧ ¬Q): the ⊕ gives T when the two previous columns have different values, and F when they are the same.
With that, the complete table looks like this:
| P | Q | R | P → Q | ¬Q | R ∧ ¬Q | (P → Q) ⊕ (R ∧ ¬Q) |
|---|---|---|---|---|---|---|
| T | T | T | T | F | F | T |
| T | T | F | T | F | F | T |
| T | F | T | F | T | T | T |
| T | F | F | F | T | F | F |
| F | T | T | T | F | F | T |
| F | T | F | T | F | F | T |
| F | F | T | T | T | T | F |
| F | F | F | T | T | F | T |
Step 6 · We read the result. We look at the last column (the ⊕, the main connective): it has T and F mixed together, so the formula is a contingency. Specifically, it is true in 6 of the 8 cases. You can check it by typing it exactly as it is, (P → Q) ⊕ R ∧ ¬Q, into the generator above.
Related calculators
Frequently asked questions
How many rows does a truth table have?
It depends on the number of distinct variables. With n variables there are 2ⁿ rows: 2 variables give 4 rows, 3 variables give 8, 4 give 16, and so on. Each row is a different combination of T/F values.
What order of precedence do the connectives follow?
From strongest to weakest: ¬ (negation), then ∧ (and), then ⊕ (xor), then ∨ (or), then → (implies) and finally ↔ (if and only if). NAND has the precedence of ∧ and NOR that of ∨. Parentheses always take priority over everything else.
What is the difference between a tautology, a contradiction and a contingency?
A tautology is true in every row (always T); a contradiction is false in every row (always F); and a contingency has both true rows and false rows. A contingency is satisfiable (there is some model) but it is not valid.
How do I check whether two formulas are equivalent?
Build the truth table of each one using the same variables. If the main connective column matches row by row, the formulas are logically equivalent. Alternatively, they are equivalent if the truth table of the biconditional between them is a tautology.
Can I use more than four variables?
Yes. The buttons show P, Q, R, S and T, but you can type any letter or name (A, B, x1, p2…). The generator supports up to 10 distinct variables (1024 rows); beyond that the table stops being readable.