Truth Table Generator
Type any logical expression and instantly generate the full truth table. Supports up to 4 variables and 6 operators: AND, OR, NOT, XOR, implication, and biconditional.
A truth table shows every possible combination of true/false values for the variables in a logical expression — and what the expression evaluates to in each case. Type your expression below using the variables A, B, C, D and the operator buttons, then click Generate. The tool also tells you whether your expression is a tautology (always true), a contradiction (always false), or contingent (depends on inputs).
What is a truth table?
A truth table is a complete, exhaustive listing of every possible combination of true/false inputs for a logical expression, paired with the result of that expression for each combination. It is the most direct method for determining whether two logical statements are equivalent, whether an argument is valid, or whether a digital circuit produces the correct output for every input.
If a logical expression has n variables, its truth table has 2n rows. One variable produces 2 rows, two variables produce 4 rows, three variables produce 8 rows, and four variables produce 16 rows. The calculator above supports up to 4 variables — beyond that, tables grow to 32 rows, 64 rows, and larger, and other techniques like Karnaugh maps or symbolic manipulation are generally preferred.
Within propositional logic, a truth table is a complete decision procedure: if the table confirms an equivalence, the equivalence is proven; if the columns differ in even one row, the equivalence fails. What truth tables do not cover is first-order logic — statements with quantifiers like “for all” or “there exists” — where other methods apply. For any finite propositional expression, however, the truth table leaves nothing to interpretation.
The term “truth table” was formalized by Ludwig Wittgenstein in his 1921 Tractatus Logico-Philosophicus and independently by the American mathematician Emil Post around the same time. The algebraic foundations trace to George Boole’s 1854 An Investigation of the Laws of Thought. The idea of cataloguing all cases of a conditional is older still: Philo of Megara, a Stoic logician of ancient Greece, worked out early truth-functional accounts of the conditional in the third century BCE.
The six logical operators
The calculator supports six operators. Five are binary (they take two inputs); NOT is unary (it acts on a single input).
AND (& or ∧)
The conjunction A & B is true only when both A and B are true. In all three other cases it is false. AND is the strictest of the binary operators — it requires both inputs to agree. In digital circuits, AND corresponds to two switches wired in series: current flows only when both switches are closed simultaneously.
OR (| or ∨)
The disjunction A | B is true when at least one of A or B is true. It is false only when both inputs are false. This is inclusive or — it remains true even when both inputs are true simultaneously. In circuits, OR corresponds to switches wired in parallel: current flows if either switch is closed.
NOT (! or ¬)
The negation !A flips the truth value: true becomes false and false becomes true. NOT is the only unary operator in classical propositional logic — it acts on a single input rather than a pair.
XOR (^ or ⊕)
The exclusive or A ^ B is true when exactly one of A or B is true — but not both. XOR is what everyday English usually means by “or” in phrases like “soup or salad,” where both options at once is not intended. XOR has one notable property: it is its own inverse. XORing a value with a key and then XORing the result with the same key again recovers the original: (A ⊕ B) ⊕ B = A. This reversibility makes XOR foundational in stream ciphers, one-time pads, and parity-based error detection.
IMPLICATION (-> or →)
The implication A -> B reads “if A then B.” It is false only when A is true and B is false. In every other case — including when A is false — it is true. The case of a false A is called vacuously true: when the premise never holds, the conditional is never broken.
Implication is the operator that confuses students most often. The key equivalence to remember: A -> B is logically identical to !A | B. The conditional is only violated when the premise is true and the conclusion fails.
BICONDITIONAL (<-> or ↔)
The biconditional A <-> B reads “A if and only if B” (often abbreviated “iff”). It is true when A and B share the same truth value — both true or both false. The biconditional is the exact negation of XOR: wherever XOR outputs true (inputs differ), the biconditional outputs false, and vice versa.
Operator precedence and summary
When multiple operators appear in an expression without parentheses, the calculator applies standard logical precedence from highest to lowest:
| Operator | Symbol | Precedence | Reads as |
|---|---|---|---|
| NOT | ! | 1 (highest) | "not A" |
| AND | & | 2 | "A and B" |
| XOR | ^ | 3 | "A xor B" |
| OR | | | 4 | "A or B" |
| IMPLICATION | -> | 5 | "if A then B" |
| BICONDITIONAL | <-> | 6 (lowest) | "A iff B" |
NOT binds the most tightly — it applies only to the immediately adjacent term. BICONDITIONAL binds the most loosely, evaluated last across the widest scope. The ranking mirrors algebra: exponentiation before multiplication, multiplication before addition.
Precedence determines meaning. The expression A | B & C is evaluated as A | (B & C) because AND outranks OR. The parenthesised version (A | B) & C produces a different truth table for certain input combinations. When the intended grouping is not obvious, add parentheses — they make intent unambiguous and never alter a correctly grouped expression.
How to read your generated table
Each row of the generated table represents one complete assignment of truth values to all variables. The leftmost columns display the variable values for that row; the rightmost column shows what the full expression evaluates to in that assignment.
Two conventions apply throughout:
- T means true, F means false. Some textbooks use 1 and 0 instead — the notation differs but the underlying logic is identical.
- The variable columns fill in binary counting order. The rightmost variable alternates every single row (T, F, T, F…); the next column to its left alternates every two rows (T, T, F, F…); and so on. This order guarantees every possible combination appears exactly once, with no row duplicated or omitted.
Building a table step by step. Take the expression ¬(A ∧ B) ∨ (A ⊕ C) with three variables — eight rows. Fill the A, B, C columns using binary counting order: A holds four T values followed by four F values; B alternates in pairs; C alternates every row. Then compute one sub-expression at a time — first (A ∧ B), then ¬(A ∧ B), then (A ⊕ C), then the final ∨. Working through intermediate sub-columns makes the process mechanical and isolates any error to the single step where it occurred.
Three things you can spot at a glance
After generating a table, the calculator classifies the expression into one of three categories:
- Tautology — every row in the result column is true. The expression is valid regardless of what the variables represent. Classic examples:
A | !A(the law of excluded middle — every proposition is either true or false);(A -> B) <-> (!B -> !A)(the law of contraposition, confirming that an implication and its contrapositive always agree). Tautologies contribute nothing to the premises of a formal argument — they are true in every possible world and carry no information about the specific case being argued. - Contradiction — every row is false. No assignment of truth values can satisfy the expression. Classic example:
A & !A(the law of non-contradiction — no proposition can be both true and false). A contradiction anywhere in a premise set is a serious problem: in classical logic, a set of premises containing a contradiction formally entails any conclusion whatsoever. - Contingent — some rows are true and some are false. The expression’s truth depends on the specific input values. Most real-world statements — about facts, events, or measurements — are contingent.
Checking logical equivalence
Two expressions are logically equivalent when their truth tables produce identical output columns across every row, built from the same set of variables. To check equivalence, compute a truth table for each expression and compare the rightmost columns row by row. If the columns agree in every row, equivalence is confirmed. If they differ in even one row, the expressions are not equivalent — no exceptions.
A foundational example is De Morgan’s laws:
¬(A ∨ B) ≡ ¬A ∧ ¬B
For the first law, a four-row table with both expressions as separate columns confirms equivalence:
| A | B | ¬(A ∧ B) | ¬A ∨ ¬B | Match? |
|---|---|---|---|---|
| T | T | F | F | ✓ |
| T | F | T | T | ✓ |
| F | T | T | T | ✓ |
| F | F | T | T | ✓ |
The columns match in every row, confirming the equivalence. De Morgan’s laws are practically useful across several fields: software engineers apply them to simplify complex conditional branches; database planners use them to restructure WHERE clauses into forms that take advantage of available indexes; circuit designers apply them when converting between NAND-based and NOR-based gate implementations.
The second law, ¬(A ∨ B) ≡ ¬A ∧ ¬B, follows the same verification approach with a four-row table. Any two expressions can be checked this way — the method is complete and mechanical.
A simpler equivalence worth knowing is double negation: ¬(¬A) ≡ A. Negating a value twice returns the original. In programming, !!value coerces any truthy expression to a strict boolean using this identity. In circuit design, two inverters wired in series cancel out. The truth table confirms it in just two rows: ¬(¬T) = T and ¬(¬F) = F.
Common mistakes
Several errors come up consistently when working with truth tables for the first time.
Treating implication as causation. A -> B is a constraint on truth values, not a claim that A produces or causes B. The statement “If the moon is made of green cheese, then 2 + 2 = 4” is logically true — the premise is false, so vacuous truth applies. This feels wrong because everyday causal reasoning doesn’t work that way, but logical implication is not causal implication. They share notation, not meaning.
Forgetting the vacuous case. When A is false, A -> B is true regardless of B. The conditional only makes a claim about what happens when the premise holds. A promise “if it rains, I’ll bring an umbrella” is not broken on a sunny day — the triggering condition never arose.
Confusing OR with XOR. Formal logic’s | is inclusive: it is true even when both inputs are true. Everyday English “or” typically implies exclusivity — soup or salad means one, not both — which is what ^ captures. When translating natural language into a logical expression, check which sense of “or” was intended before choosing the operator.
Unbalanced parentheses. The calculator reports a parse error when parentheses do not match. Every opening parenthesis requires exactly one closing parenthesis. Building a complex expression incrementally — one operator at a time, testing after each addition — keeps errors small and easy to locate.
Using lowercase variable names. Only the uppercase letters A, B, C, and D are recognised as variables. Lowercase letters and any other characters cause a parse failure. If an expression triggers an unexpected error, check for lowercase letters before investigating anything else.
Where truth tables are used
Truth tables are a working tool in several disciplines, not only a classroom exercise.
Digital circuit design. Every logic gate in a processor — AND, OR, XOR, NOT, NAND, NOR — implements one row of a truth table in silicon. Engineers specify the intended behaviour of a circuit by writing a truth table for it before any hardware is designed. NAND gates are particularly important: they are functionally complete, meaning any logic function can be built from NAND gates alone. This universality is why NAND flash memory uses that gate type — the same physical structure that stores data can also implement the access logic required to read and write it.
Software and code review. Conditional expressions like if (isAuthorised && !isExpired || isAdmin) can be difficult to reason about informally. Mapping such a condition to a truth table reveals unreachable branches — input combinations that can never occur — along with logical redundancies and subtle operator-precedence bugs. The table makes implicit assumptions explicit and gives a complete picture of how the condition behaves across every case.
Database query optimisation. SQL WHERE clauses combine conditions with AND, OR, and NOT. Query planners apply boolean identities — including transformations equivalent to De Morgan’s laws — to restructure those clauses into execution plans that use indexes more efficiently or scan fewer rows. The reason two SQL queries that look different can produce the same results is that they express logically equivalent boolean expressions; a truth table comparison would show identical output columns.
Philosophy and formal argument. A deductive argument is valid when the conclusion is true in every row where all premises are true. Truth tables make this mechanical to check: construct a table with a column for each premise and a column for the conclusion, identify the rows where every premise is true, then verify the conclusion column in those rows. If the conclusion is false in any such row, the argument is invalid. The method requires no logical intuition — only the table.
Cryptography and error correction. XOR’s reversibility — (A ⊕ B) ⊕ B = A — makes it the core operation of one-time pads and stream ciphers. In a one-time pad, a plaintext bit is XORed with a random key bit to produce ciphertext; the receiver recovers the plaintext by XORing the ciphertext with the same key. Parity bits use XOR to detect single-bit transmission errors: XOR all transmitted bits together; if the result differs at the receiver, a bit was flipped. Hamming codes extend this to locate and correct errors, applying the same truth-table logic at scale.