Skip to content

Digital Logic

How to make a truth table

A truth table lists every possible combination of a logic circuit's inputs, one per row, with the output each one gives. Because every case is there, it's the circuit's whole rule, with nothing left to argue about. To make one: count the rows, list the inputs in binary order, then work out the output for each row.

Step 1: count the rows

Each input can be 0 or 1, and each extra input doubles the combinations. With n inputs there are 2ⁿ rows: 4 for two inputs, 8 for three, 16 for four.

Step 2: list the inputs in order

Count up in binary, so no row is missed or repeated. For two inputs: 00, 01, 10, 11. Here is OR, which gives 1 when at least one input is 1:

ABA OR B
000
011
101
111

Set it beside AND's table, which has a single 1 on the last row, and OR has the opposite habit: a single 0 on the first.

Live experiment

What's in the box?

A gate hides in a closed box. Flip the two switches, watch Pip on its output and fill in the table, then guess: AND or OR? Box 3 has a surprise inside, a circuit with no OR gate at all. Check its table against OR's.

Try it yourself: free lesson

“OR, and the table” is lesson 3 of 6 in Gate Grove, Digital Logic World 1. Free with an account. Lessons unlock in order, so you’ll do the 2 before it first.

Step 3: work out each output

For a circuit with more than one gate, add a column for each gate's output and fill the table left to right. A smoke alarm that sounds for SMOKE, HEAT or TEST, ALARM = (SMOKE + HEAT) + TEST, has eight rows:

SMOKEHEATTESTSMOKE + HEATALARM
00000
00101
01011
01111
10011
10111
11011
11111

Seven 1s and one 0: silent only when all three are off. The middle column is the first OR gate's output, which the second OR combines with TEST.

What a table is for

Identifying a gate. You don't need to see inside a box. Flip the inputs, read the outputs, and match the table. A single row can be enough: one input on and one off lights an OR but never an AND.

Proving circuits equal. Two circuits with the same table do the same job, whatever they're built from. Put NOTs on both inputs of an AND and a NOT on its output, and the table comes out identical to OR's.

Designing. Engineers often write the table first, as the promise, then pick gates that keep it. Any table can be turned into gates by ORing one AND term for each row that gives a 1.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“OR, and the table” is lesson 3 of 6 in Gate Grove, Digital Logic World 1. Free with an account. Lessons unlock in order, so you’ll do the 2 before it first.

Or start from the very first lesson, no account needed

Work it out

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3An OR gate's inputs are 1 and 1. Its output is…
    Show the answer

    Answer: 1. OR means at least one. Both is more than at least one, so the output is 1. Only 0 and 0 gives 0.

    • Why not “2”? A gate's output is a single bit, 1 or 0. OR doesn't add, so two 1s give 1, not 2.
    • Why not “It depends”? A gate's output depends only on its inputs, and 1 and 1 always give 1 from OR.
    • Why not “0”? OR gives 0 only when both inputs are 0. With both at 1, at least one is 1, so the output is 1.
  2. Question 2 of 3A box hides a gate. With one switch on and the other off, its probe lights. The gate is…
    Show the answer

    Answer: OR: one input on its own is enough. AND gives 0 for 01 and 10, so it could never light there. OR gives 1 for any line with a 1 in it. One line of the table was enough to tell them apart.

    • Why not “NOT”? NOT has only one input, and this box has two switches feeding it.
    • Why not “AND: it needs both”? AND gives 0 for 01 and 10, so it could never light with one switch on and the other off.
    • Why not “Can't tell without opening the box”? One row is enough here: of the two, only OR gives 1 with exactly one input on.
  3. Question 3 of 3OR gates here have two inputs. To OR three signals you need…
    Show the answer

    Answer: Two OR gates, one feeding the other. OR two of them, then OR the result with the third. Same trick as the two-hand press, with ORs.

    • Why not “An AND gate”? An AND would need all three on at once. An alarm should sound for any one of them.
    • Why not “One OR gate”? One 2-input OR has room for only two signals, so the third needs a second gate.
    • Why not “Three OR gates”? Two are enough: OR the first two, then OR that result with the third.
Keep practising: free lesson

“OR, and the table” is lesson 3 of 6 in Gate Grove, Digital Logic World 1. Free with an account. Lessons unlock in order, so you’ll do the 2 before it first.

Questions people ask

How many rows does a truth table have?

2 to the power of the number of inputs, because each input doubles the combinations. One input has 2 rows, two have 4, three have 8, four have 16, and ten inputs would need 1,024.

What order should the rows go in?

Count up in binary, with the first input as the leftmost bit: 000, 001, 010 and so on to 111. The rightmost column then alternates every row and the leftmost changes only halfway down, so no combination is missed or repeated.

Can two different circuits have the same truth table?

Yes, and then they do exactly the same job. NOT A AND NOT B, with a NOT on the output, has OR's table, which is De Morgan's law. Engineers write the table first and choose the cheapest circuit that matches it.

Every topic