Truth Table Calculator (Propositional Logic)

Type a propositional formula and this calculator enumerates every assignment of its variables, evaluates each sub-formula in turn, and tells you whether the result is a tautology, a contradiction or a contingency. It accepts words (AND, OR, NOT, XOR, NAND, NOR, IMPLIES, IFF), programming symbols (&&, ||, !, ^, ->, <->) and the logic symbols themselves. Every intermediate column is shown, so you can check a hand-drawn table row by row rather than just comparing a final answer.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Logical formulaUse letters for variables and any of AND, OR, NOT, XOR, NAND, NOR, IMPLIES, IFF or their symbols.(p AND q) OR (NOT p AND r)
Notation for column headingsChanges only how the parsed formula and the table headings are displayed, never the result.Symbols (¬ ∧ ∨ ⊕ → ↔)
Show a column for every sub-formulaLeave this on to check a hand-built table column by column; turn it off for just the final result.Yes

It returns

  • Classification — Tautology means true in every row, contradiction means true in none, contingency means some of each.
  • Rows where the formula is true
  • Total rows
  • Distinct variables
  • Formula as parsed
  • Satisfying assignments

The formula

R=2n
pq¬pq
pq(pq)(qp)

In plain text: R = 2^n (rows in a truth table over n variables)

  • RNumber of rows the table needs (rows)
  • nNumber of distinct propositional variables in the formula (variables)

Every connective is defined by its own two-row or four-row table; the calculator applies those definitions to each row in turn.

Updated Category Discrete Math, Logic & Graph Theory Verified against published test cases Reading time 12 min

What a truth table actually settles

A truth table is an exhaustive proof by cases. Classical propositional logic makes one strong assumption — every proposition is either true or false, with nothing in between — and that assumption turns any question about a formula into a finite search. If a formula has n distinct variables, there are exactly 2n ways to assign truth values to them, and checking all of them settles the question completely.

Three verdicts are possible, and they are the three this calculator reports. A tautology is true in every row: it says nothing about the world, which is precisely why it is useful as a law of logic. A contradiction is true in no row; its negation is a tautology. A contingency is true in some rows and false in others, which means its truth depends on facts the formula alone does not settle.

Two further questions reduce to the same table. Two formulas are logically equivalent exactly when the biconditional joining them is a tautology, so you can test the equivalence of A and B by entering A <-> B and looking for a tautology verdict. An argument with premises P₁…Pk and conclusion C is valid exactly when (P1 AND P2 AND … ) -> C is a tautology. One tool, three jobs.

How each connective is defined, and why implication looks wrong

Each connective is a function from truth values to truth values, and the table below is its complete definition. Negation flips a value. Conjunction is true only when both parts are true. Disjunction in logic is inclusive: p ∨ q is true when both hold, unlike the everyday "or" that often means one or the other. Exclusive-or is the connective that captures the everyday sense, and it is true exactly when the two operands differ.

Material implication is where nearly every student stops and objects. p → q is false in exactly one row — p true and q false — and true in the other three, including both rows where p is false. So "if the moon is cheese then 2 + 2 = 5" comes out true. That feels wrong because natural-language conditionals carry a claim of relevance that the truth-functional connective does not.

The reason logic keeps this definition is that it is the only truth-functional connective that never lets you infer a falsehood from truths. A conditional must be false when the antecedent holds and the consequent fails; if it were also false in some row where the antecedent fails, then p → q would depend on facts irrelevant to the inference, and the rule of modus ponens would stop being sound. The equivalence p → q ≡ ¬p ∨ q is the compact way to remember the whole table: the conditional asserts only that you do not get p without q.

The biconditional is the conjunction of both directions, so it is true exactly when the two sides agree. NAND and NOR are the negations of conjunction and disjunction; each on its own is functionally complete, meaning every connective can be rebuilt from it alone, which is why physical gate libraries are built around them. If you want the minimal gate expression rather than the table, use the Boolean algebra simplification calculator.

Worked example: is (p ∧ q) → (p ∨ q) a tautology?

Two variables give 2² = 4 rows. Work outward from the innermost sub-formulas, one column at a time, exactly as the calculator does.

  1. List the rows. With p and q in that order the assignments are TT, TF, FT, FF.
  2. Column for p ∧ q. True only when both are true: T, F, F, F.
  3. Column for p ∨ q. True unless both are false: T, T, T, F.
  4. Column for the whole conditional. Apply the implication table to the two columns you just built, row by row. Row 1: T → T = T. Row 2: F → T = T. Row 3: F → T = T. Row 4: F → F = T.
  5. Read the verdict. All four rows are true, so the formula is a tautology: 4 true rows out of 4.

Now change one symbol and redo it. For (p ∨ q) → (p ∧ q), the antecedent column is T, T, T, F and the consequent is T, F, F, F. Row by row: T → T = T, T → F = F, T → F = F, F → F = T. Two rows out of four are true, so this is a contingency, not a tautology. The falsifying rows are exactly TF and FT — the rows where p and q disagree, which is the same set of rows where p ⊕ q is true. Swapping the antecedent and consequent of a conditional is not a valid move, and the table shows you precisely where it breaks.

How to read the verdict, and what to do next

Read the classification first, then the count. Tautology means the formula is a law: it holds under every interpretation, so it can be added to a proof at any point. If you built the formula as premises -> conclusion, a tautology verdict is a proof that the argument is valid.

Contradiction means the formula is unsatisfiable. If you built it as the conjunction of a set of constraints, that verdict tells you the constraints cannot all hold at once — and it is the same question a SAT solver answers, just settled by brute force instead of by search. Contingency means the formula is satisfiable but not valid; the satisfying assignments the calculator lists are exactly the models you can use as a witness.

The count of true rows carries extra information. A formula over n variables with t true rows corresponds to a Boolean function with t minterms, and the ratio t / 2n is sometimes called the density of the function. A formula that is true in exactly half its rows is balanced — negation, exclusive-or and the identity function are all balanced, and so is any formula equivalent to a single literal.

If your verdict is contingency but you expected a tautology, find the first false row and read the variable assignment across it. That single row is a counter-example, and it is normally enough to see which step of your reasoning failed. This is why the sub-formula columns matter: the row tells you the assignment, and the columns tell you which sub-formula first went the wrong way.

The complete truth tables for every connective this calculator accepts

All eight connectives on two variables. ¬p depends only on p and is repeated for reference.
pq¬pp ∧ qp ∨ qp ⊕ qp → qp ↔ qp ↑ q (NAND)p ↓ q (NOR)
TTFTTFTTFF
TFFFTTFFTF
FTTFTTTFTF
FFTFFFTTTT

Memorise two rows and derive the rest: conjunction is true only in the first row, disjunction is false only in the last, and implication is false only in the second.

Precedence, brackets and the errors they cause

This calculator binds the connectives in the conventional order, tightest first: ¬, then ∧ and NAND, then ⊕, then ∨ and NOR, then →, then ↔. Implication associates to the right, so p -> q -> r parses as p → (q → r); the other binary connectives associate to the left. The Formula as parsed output shows you exactly how your input was grouped, and you should read it before you trust the table.

Precedence is where most disagreements between a hand-drawn table and a generated one come from. NOT p AND q parses as (¬p) ∧ q, not as ¬(p ∧ q), and those two formulas differ in two of the four rows. Textbooks vary on where exclusive-or sits, and some place it at the same level as disjunction. If your source uses a different convention, add brackets — an over-bracketed formula is never ambiguous, and it costs you nothing.

A second common source of mismatch is variable naming. P and p are different variables here, so P OR NOT p has four rows and is a contingency, while p OR NOT p has two rows and is a tautology. Variables are listed in alphabetical order in the table, which is why the columns may not appear in the order you typed them.

Mistakes that make a hand-built table disagree with this one

  • Reading implication backwards. p → q is false only in the row where p is true and q is false. If your column has two Fs, you have probably built the biconditional instead.
  • Treating ∨ as exclusive. Logical disjunction is true when both disjuncts hold. Use XOR when you mean one or the other but not both.
  • Dropping brackets around a negated compound. NOT p AND q and NOT (p AND q) agree only in the two rows where q is false.
  • Skipping a row. With n variables you need exactly 2n rows: 8 for three variables, 16 for four. A table with 6 rows for three variables is missing two cases and can report a false tautology.
  • Reusing a variable letter for two different propositions. Each distinct letter gets its own column, and each occurrence of the same letter must take the same value in a row.
  • Assuming a tautology in one direction gives you the other. (p ∧ q) → (p ∨ q) is valid; the converse is not. Test both directions separately, or test the biconditional.

What truth tables cannot do, and what to use instead

The method is complete for propositional logic and useless beyond it. A truth table cannot evaluate quantifiers: "every prime greater than two is odd" has no finite table because it ranges over an infinite domain, and deciding it needs first-order proof methods, not enumeration. Nor can it handle modal operators, probabilities, or any many-valued logic in which a proposition can be other than true or false.

The cost is the other limit. The table doubles with each variable: 10 variables give 1,024 rows, 20 give more than a million, and 40 give more than a trillion. That growth is why this calculator stops at six variables and why real satisfiability problems are attacked with DPLL and CDCL solvers, which prune the search rather than enumerating it. Deciding satisfiability of a propositional formula is the original NP-complete problem, so no method is known that avoids exponential worst-case behaviour — see the Big-O growth comparison calculator for how 2n compares with the growth rates you meet elsewhere.

For the related engineering questions there are better tools than a table. To turn a table into the cheapest two-level circuit, use a Karnaugh map solver, which is the graphical form of the same enumeration. To reason about collections rather than propositions, the algebra is the same but the objects are different — the set operations calculator applies the identical De Morgan laws to unions and intersections. And when your propositions describe steps of a recursive process rather than a fixed circuit, the linear recurrence relation calculator is the right instrument.

Key terms

Valuation (assignment)
One complete choice of truth value for every variable — that is, one row of the table.
Tautology
A formula true under every valuation. Also called logically valid. Its negation is a contradiction.
Satisfiable
True under at least one valuation. Every tautology and every contingency is satisfiable; contradictions are not.
Logical equivalence
Two formulas have identical columns in every row. Equivalently, the biconditional joining them is a tautology.
Functional completeness
A set of connectives from which every truth function can be built. {¬, ∧} is complete; so is {NAND} on its own, and so is {NOR}.
Minterm
A row in which the formula is true, written as a conjunction of literals. The count of minterms is the true-row count this calculator reports.

Frequently asked questions

How many rows should my truth table have?

Exactly 2 raised to the number of distinct variables: 2 rows for one variable, 4 for two, 8 for three, 16 for four, 32 for five and 64 for six. The count depends only on how many different letters appear, not on how long the formula is or how many times each letter is repeated. If your row count is not a power of two, you have missed a case.

Why is p → q true when p is false?

Because a conditional only promises that you never get the antecedent without the consequent, and that promise is not broken by a row where the antecedent fails. Formally p → q is equivalent to ¬p ∨ q. This is called material implication, and it deliberately ignores any relevance between p and q — which is why the everyday sense of "if" and the logical connective come apart in the two rows where p is false.

How do I check whether two formulas are logically equivalent?

Join them with a biconditional and look for a tautology verdict. Enter A <-> B — for example NOT (p AND q) <-> (NOT p OR NOT q) — and if every row is true the two formulas are equivalent. If the verdict is contingency, any false row is a valuation on which they disagree, and reading the sub-formula columns across that row shows you where.

Can I test whether an argument is valid?

Yes. Write the conjunction of the premises, then an implication arrow, then the conclusion: (p -> q) AND p -> q tests modus ponens. A tautology verdict means the argument is valid — no valuation makes the premises true and the conclusion false. A contingency verdict means the argument is invalid, and every false row is a counter-example you can quote.

What is a normal number of true rows?

There is no normal, but the count is informative. Zero true rows means the formula is unsatisfiable; all rows true means it is a law. Half the rows true is what you get from a single literal, from exclusive-or, and from the biconditional. A formula true in most but not all rows is often a conditional, because implication is false in only one of its four rows and that skew propagates.

Which symbols and words does the calculator accept?

Words: AND, OR, NOT, XOR, NAND, NOR, IMPLIES, IFF, XNOR, TRUE, FALSE. Symbols: ¬ ~ ! for negation; ∧ · & * && for conjunction; ∨ | + || for disjunction; ⊕ ^ for exclusive-or; → ⇒ -> => for implication; ↔ ≡ <-> <=> for the biconditional; ↑ for NAND and ↓ for NOR. Round or square brackets both group. Case does not matter for the operator words, but it does for variable names.

Why does the calculator stop at six variables?

Because the table doubles with every variable and stops being readable. Six variables give 64 rows; ten would give 1,024 and twenty over a million. Beyond a handful of variables, enumerating every row is the wrong technique — satisfiability solvers prune the search space instead. If your problem genuinely has ten variables, look for structure you can factor out rather than a bigger table.

Do the sub-expression columns change the answer?

No. Turning them off changes only what is displayed; the final column and the verdict are identical either way. Keep them on while you are checking work by hand, because they let you locate the first column where your table and this one diverge instead of only knowing that the answers differ.

Is a contradiction the same as a false statement?

No. A false statement is false as a matter of fact; a contradiction is false as a matter of form, in every row of the table, whatever the facts. "It is raining" can be false today and true tomorrow, so it is a contingency. "It is raining and it is not raining" is false under every valuation, so it is a contradiction — and its negation is a tautology.

References

  • Discrete Mathematics and Its Applications, 8th ed., Chapter 1: The Foundations — Logic and Proofs — McGraw-Hill (Kenneth H. Rosen)
  • A Mathematical Introduction to Logic, 2nd ed. — Academic Press (Herbert B. Enderton)
  • Digital Design: With an Introduction to the Verilog HDL, VHDL and SystemVerilog, 6th ed. — Pearson (M. Morris Mano and Michael D. Ciletti)
  • Introduction to Algorithms, 4th ed. — NP-completeness and satisfiability — MIT Press (Cormen, Leiserson, Rivest, Stein)