CompSci.rocks
LearnLogic

Truth Table Practice

Practice filling out truth tables for boolean expressions built from AND, OR, and NOT, with randomly generated problems and instant row-by-row feedback.

A truth table lists every possible True/False combination of a boolean expression's variables, and shows what the expression evaluates to for each one. They show up in intro programming (every if condition is a boolean expression), discrete math, and digital logic design, and the only way to get quick at reading them is to fill out a lot of them.

Truth Table Practice

Work out whether the expression below is True or False for each row, select your answer, then click Check Answers. Rows go from every variable True at the top down to every variable False at the bottom.

The three operators

Every expression on this page is built from three operators, using the same &&, ||, and ! symbols you'd use in Java, JavaScript, or Python's and/or/not.

NOT (!) flips a single value: True becomes False, and False becomes True.

A!A
TrueFalse
FalseTrue

AND (&&) is True only when both sides are True.

ABA && B
TrueTrueTrue
TrueFalseFalse
FalseTrueFalse
FalseFalseFalse

OR (||) is True when at least one side is True — it's only False when both sides are False.

ABA || B
TrueTrueTrue
TrueFalseTrue
FalseTrueTrue
FalseFalseFalse

Building a table for a bigger expression

Step 1 — Count the variables and figure out how many rows you need. Each variable can be True or False, so an expression with n distinct variables needs 2^n rows to cover every combination — 2 variables need 4 rows, 3 need 8, 4 need 16.

Step 2 — List every combination systematically, without skipping or repeating one. This page lists rows starting with every variable True at the top, then works down to every variable False at the bottom, flipping the rightmost variable every row, the next one every 2 rows, and so on — the same pattern as counting down in binary.

Step 3 — Respect operator precedence. ! happens first, then &&, then ||, unless parentheses say otherwise — exactly like multiplication happening before addition in arithmetic. A || B && C means A || (B && C), not (A || B) && C.

Step 4 — Work from the innermost parentheses outward. For a nested expression like A && (B || C), evaluate B || C first for that row, then AND the result with A.

Worked example

Let's build the table for A && (B || C). Three variables means 8 rows.

A B C B || C A && (B || C)
True True True True True
True True False True True
True False True True True
True False False False False
False True True True False
False True False True False
False False True True False
False False False False False

Notice the last four rows are all False — once A is False, A && anything is False no matter what B and C are doing. That's a handy shortcut once you're comfortable with the full method: if an AND has a False operand, or an OR has a True operand, you already know the answer for that side without working out the rest.

Common mistakes to watch for

  • Evaluating left to right instead of by precedence. ! binds tighter than &&, which binds tighter than ||. Work those out before combining anything with ||.
  • Applying ! to the wrong thing. !A && B only negates A — it's not the same as !(A && B), which negates the whole expression.
  • Losing track of a row count. If your table doesn't have exactly 2^n rows for n variables, or two rows list the same combination, you've made a bookkeeping mistake somewhere.
  • Misreading nested parentheses. Work from the innermost set outward, one operator at a time, instead of trying to evaluate the whole expression at once.