Logic

Truth Table Generator

Type any Boolean expression and get its full truth table at once, with a column for every step. Works with AND, OR, NOT, XOR, NAND, NOR, implication and biconditional, in logic symbols, engineering notation or plain words. It also gives the minterms, maxterms and canonical SOP and POS forms.

Write AND as AND, &, *, ∧ or letters side by side (AB); OR as OR, |, +, ∨; NOT as NOT, !, ~, ¬ or A'.

How to make a truth table

  1. List the variables. With n variables there are 2n rows: 4 rows for 2 variables, 8 for 3, 16 for 4.
  2. Fill in every combination. Count in binary: the last variable alternates 0, 1, 0, 1; the one before it changes every 2 rows, then every 4, and so on. That way no combination is missed.
  3. Add a column for each step, innermost brackets first. For (A ∧ B) ∨ ¬C, work out A ∧ B and ¬C, then combine them with ∨.
  4. The last column is the answer. If it is always 1 the expression is a tautology; always 0 is a contradiction.

Logical operators and their truth tables

ABNOT A
¬A
AND
A ∧ B
OR
A ∨ B
XOR
A ⊕ B
NAND
A ↑ B
NOR
A ↓ B
IMPLIES
A → B
IFF
A ↔ B
0010001111
0110111010
1000111000
1101100011

The one that surprises people is implication: A → B is only false when A is true and B is false. "If it rains, the ground is wet" is not broken on a dry day without rain. AND, OR and NOT are also the Boolean operators of the AP CSP exam; practise them in the AP CSP pseudocode runner.

How to type expressions

OperatorYou can type
NOTNOT A !A ~A ¬A A'
ANDA AND B A & B A && B A * B A ∧ B AB
ORA OR B A | B A || B A + B A ∨ B
XORA XOR B A ^ B A ⊕ B
NAND / NORA NAND B A ↑ B / A NOR B A ↓ B
ImpliesA -> B A => B A → B A IMPLIES B
If and only ifA <-> B A ↔ B A == B A IFF B A XNOR B
Constants0 1 true false

Order of operations, strongest first: NOT, AND, XOR, OR, implies, if and only if. Variables are a letter with optional digits (A, p, x1), so AB means A AND B. Use brackets whenever you are not sure.

Print a truth table in Python

itertools.product gives every combination of True and False, which is exactly the rows of a truth table. Press Run this code, then change f to your own expression.

truth_table.py Run this code
from itertools import product

# Truth table of (A and B) or not C
def f(A, B, C):
    return (A and B) or (not C)

print("A B C | F")
for A, B, C in product([False, True], repeat=3):
    row = [int(A), int(B), int(C)]
    print(*row, "|", int(f(A, B, C)))

Frequently asked questions

How many rows does a truth table have?

2 to the power of the number of variables: 4 rows for 2 variables, 8 for 3, 16 for 4. This generator handles up to 8 variables (256 rows).

What symbols can I use?

Words (AND, OR, NOT, XOR, NAND, NOR, IMPLIES, IFF), programming symbols (&, |, !, ^, ->), logic symbols (∧, ∨, ¬, ⊕, →, ↔) or engineering notation (AB for AND, + for OR, A' for NOT). You can mix them.

What is a tautology?

An expression that is true in every row of its truth table, such as p ∨ ¬p or (p → q) ↔ (¬q → ¬p). An expression that is false in every row is a contradiction.

What are minterms and maxterms?

A minterm is a row where the expression is true, numbered by its binary value; a maxterm is a row where it is false. The canonical SOP is the OR of all minterms, and the canonical POS is the AND of all maxterms.

Can I show T and F instead of 1 and 0?

Yes. Pick T and F under Values, and choose whether the table starts with 0 / F or with 1 / T.

Is it free?

Yes. It runs in your browser, is free and needs no account. You can share a table with the link in the address bar.