LogicGates.org Open the simulatorSimulator

Truth tables for logic statements

Type a statement from propositional logic, such as p → q, and get its full truth table with a column for every step. Several statements at once are checked for equivalence, and premises followed by ∴ and a conclusion are checked for validity.

¬ ~ ! not, ∧ & ^ and, ∨ | v or, → -> => if-then, ↔ <-> iff if and only if, ⊕ xor. Separate statements with , to compare them; put ∴ or therefore before a conclusion to test an argument.

Tautology Here all 4 rows come out T in the last column. A tautology is a statement that is true in every row, whatever its letters stand for. More on this
pq p → q ¬q (p → q) ∧ ¬q ¬p (p → q) ∧ ¬q → ¬p
TT T F F F T
TF F T F F T
FT T F F T T
FF T T T T T
Rows
Working
Disjunctive normal form (DNF): an OR of ANDs ⊤
Conjunctive normal form (CNF): an AND of ORs ⊤
Full (canonical) DNF and CNF
Full DNF: one AND for each row where it is true (¬p ∧ ¬q) ∨ (¬p ∧ q) ∨ (p ∧ ¬q) ∨ (p ∧ q)
Full CNF: one OR for each row where it is false ⊤

What these are. The same thing for circuits: sum of products and product of sums.

Expression tree

How the statement is built, with the value of each part when p = T, q = T. Click a row of the table to pick another.

(p → q) ∧ ¬q → ¬p = T (the whole expression)→T (p → q) ∧ ¬q = F∧F p → q = T→T p = TpT q = TqT ¬q = F¬F q = TqT ¬p = F¬F p = TpT

The five connectives

Every statement in propositional logic is built from single letters and these five. Each is defined by nothing more than its truth table.

Negation¬p

p ¬p
T F
F T

Read "not p": flips the truth value.

Conjunctionp ∧ q

pq p ∧ q
TT T
TF F
FT F
FF F

Read "p and q": true only when both are true.

Disjunctionp ∨ q

pq p ∨ q
TT T
TF T
FT T
FF F

Read "p or q": true when at least one is true.

Conditionalp → q

pq p → q
TT T
TF F
FT T
FF T

Read "if p then q": false only when p is true and q is false.

Biconditionalp ↔ q

pq p ↔ q
TT T
TF F
FT F
FF T

Read "p if and only if q": true when both have the same value.

How to build a truth table by hand

  1. Count the letters. With n different statement letters there are 2n rows: 4 for p and q, 8 once r joins them.
  2. Fill in the letter columns. The first letter is true for the top half and false for the bottom half, the next alternates in quarters, and the last alternates every row. That lists every combination once.
  3. Work from the inside out. Give each part of the statement its own column, innermost brackets and negations first, and fill it using the connective's table and the columns it depends on.
  4. Read the last column. That is the value of the whole statement in each row.

Here is (p → q) ∧ ¬q → ¬p worked that way, which is the reasoning called modus tollens written as one statement:

pq p → q ¬q (p → q) ∧ ¬q ¬p (p → q) ∧ ¬q → ¬p
TT T F F F T
TF F T F F T
FT T F F T T
FF T T T T T

The last column is true in every row, so the statement is a tautology: true whatever p and q are. One that is false in every row, such as p ∧ ¬p, is a contradiction, and anything in between is a contingency. More on these, with the famous tautologies, on the tautology page.

Converse, inverse and contrapositive

Swap or negate the parts of a conditional and you get three related statements. Only one of them says the same thing.

pq Conditional
p → q
Converse
q → p
Inverse
¬p → ¬q
Contrapositive
¬q → ¬p
TT T T T T
TF F T T F
FT T F F T
FF T T T T

The conditional and its contrapositive match in every row, so they are logically equivalent, and so are the converse and the inverse. A conditional and its converse are not: "if it is a square, it has four sides" is true, and "if it has four sides, it is a square" is not. See conditional statements for "only if", "unless" and the biconditional, and the table of logical equivalences for the other laws.

Testing an argument

An argument is valid when its conclusion is true in every row where all its premises are true. To test one, look only at those rows. Take p → q and q, therefore p:

pq p → qq ∴ p
TT T T T
TF F F T
FT T T F
FF T F F

Both premises are true in 2 rows, and in the red one the conclusion is false: q is true and p is not. That single counterexample makes the argument invalid. It is a named fallacy, affirming the consequent. Swap the second premise for p and conclude q instead and you have modus ponens, which is valid: check it. The other valid forms, and how to chain them into a proof, are on the rules of inference page.

Normal forms: DNF and CNF

Every statement can be rewritten using only ¬, ∧ and ∨ in one of two standard shapes. The disjunctive normal form (DNF) is an OR of ANDs, such as (p ∧ q) ∨ ¬r. The conjunctive normal form (CNF) is an AND of ORs, such as (p ∨ q) ∧ ¬r. In both, ¬ only ever sits directly on a letter.

Both can be read straight off the truth table. The full (canonical) DNF has one AND term for each row where the statement is true, naming every letter, true or negated as in that row. The full CNF has one OR clause for each row where the statement is false, which rules that row out. The calculator shows those, and shorter forms found by merging terms that differ in one letter. A contradiction has no true rows, so its DNF is ⊥; a tautology has no false rows, so its CNF is ⊤. CNF is the input format of SAT solvers and of resolution proofs. In circuit design the same two shapes are called sum of products and product of sums.

The same tables, as logic gates

Propositional logic and digital circuits share one algebra. Write 1 for T and 0 for F, and ∧, ∨ and ¬ are the AND, OR and NOT gates. The conditional has no gate of its own, since p → q is ¬p ∨ q, and the biconditional is the XNOR gate. Laws such as De Morgan's hold in both. For circuit expressions, where ab means a AND b, use the truth table generator.

Questions

How do I type the symbols?

Any common notation works. NOT: ¬, ~, ! or not. AND: ∧, &, ^ or and. OR: ∨, |, + or the word or, and a lone v between two letters works too. IF-THEN: →, ->, =>, ⊃ or implies. IF AND ONLY IF: ↔, <->, <=>, ≡ or iff. XOR: ⊕. Each statement letter is a single letter such as p, q or r, and ⊤ and ⊥ (or true and false) are constants.

Why is "if p then q" true when p is false?

Because a conditional only makes a promise about what happens when p is true. When p is false the promise is not broken, whatever q is, so the statement counts as true; logicians call this vacuously true. The only row that breaks "if it rains, the street is wet" is the one where it rains and the street stays dry.

How many rows does a truth table need?

Two to the power of the number of statement letters: 2 rows for one letter, 4 for two, 8 for three, 16 for four. This calculator goes up to 6 letters, which is 64 rows.

Which order do the rows go in?

Logic textbooks start from all true and end with all false, halving the pattern in each column: the first letter is TTTTFFFF for three letters, the next TTFFTTFF, the last TFTFTFTF. Computer science counts up in binary from all zeros instead. Both list every combination exactly once; switch between them with the order option.

How do I check whether an argument is valid?

Type the premises separated by commas, then ∴ (or "therefore") and the conclusion, as in "p → q, p ∴ q". The argument is valid when every row that makes all the premises true also makes the conclusion true. A row where the premises are true and the conclusion false is a counterexample, and one is enough to make it invalid.

How do I show two statements are logically equivalent?

Separate them with commas. They are equivalent when their columns match in every row, or equally when the biconditional between them is a tautology. The contrapositive example shows p → q and ¬q → ¬p agreeing everywhere, while the converse q → p does not.

How do I find the DNF or CNF of a statement?

Type the statement on its own and the calculator lists both under the table. By hand, take the rows where the statement is true and write an AND of the letters for each (negating the false ones), then join them with OR: that is the full DNF. For the full CNF, take the rows where it is false and write an OR of the letters for each, negating the true ones, then join those with AND. Simplify with the laws of logic for the shorter forms.

Is this the same as a logic gate truth table?

Yes, with different notation. T and F are 1 and 0, ∧ is an AND gate, ∨ is OR and ¬ is NOT. The conditional p → q has no gate of its own; it is ¬p ∨ q. The biconditional is an XNOR gate. For circuit expressions the truth table generator uses the engineering notation, where ab means a AND b.