The six logic gates
Inside a computer, every decision is made by circuits that work with signals that are either on (1) or off (0). Each one is a logic gate: it takes one or two binary inputs (0 = off / false, 1 = on / true) and gives one binary output.
Every circuit you will meet is built from these six. Know each one's symbol, truth table and expression, with the gate names written as words. OR gives 1 when both inputs are 1; XOR does not.
NOT
| A | X |
|---|---|
| 0 | 1 |
| 1 | 0 |
Output is the opposite of the input. One input only.
AND
| A | B | X |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Output is 1 only if both inputs are 1.
OR
| A | B | X |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Output is 1 if at least one input is 1 (including both).
NAND
| A | B | X |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NOT AND: output is 0 only if both inputs are 1.
NOR
| A | B | X |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
NOT OR: output is 1 only if both inputs are 0.
XOR (EOR)
| A | B | X |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Exclusive OR: output is 1 only if the inputs are different.
Shaded rows: the inputs that give an output of 1.
1 A = 1 and B = 0. Give the output of AND, OR, NAND and XOR.
2 Which two gates give 1 when both inputs are 0?
3 Which gate gives 1 only when both inputs are 0?
- 1AND 0, OR 1, NAND 1, XOR 1
- 2NAND and NOR
- 3NOR (NOT OR)
Logic conventions: symbols, rules and words
A circuit drawing is only useful if everyone who reads it sees the same circuit. Draw each gate with its exact shape, and turn each joining word in a statement into its operator.
Drawing the symbols
Several shapes differ only in a small detail, so draw each gate so that it cannot be confused with the others.
AND
Flat back, round front.
OR
Curved back, pointed front.
NAND · NOR
AND or OR with a small circle on the output: the circle means NOT.
XOR
OR with an extra curved line across the inputs.
Rules for drawn circuits
Right gates can still make a wrong circuit if two wires look joined or a gate gets three inputs. Three rules prevent that:
Two inputs per gate
Every drawn gate except NOT has two inputs. Three conditions all needed → (A AND B) AND C: chain two AND gates.
Junction dots
Draw each input once and branch it at a dot. Wires that cross without a dot are not connected.
Do not simplify
Draw the expression as given: NOT (A AND B) is an AND gate then a NOT gate, not one NAND gate.
Turn the words into operators
Most problems describe the logic in words, not symbols. Find the joining words and write the operator each one means.
| The statement says… | Use | Example |
|---|---|---|
| both … and … | AND | the card and the PIN are valid → A AND B |
| either … or … (or both) | OR | the button is pressed or the sensor is triggered → A OR B |
| opposite to the defined 1 state | NOT | the door is not locked → NOT L |
| only one of … (not both) | XOR | exactly one switch is on → A XOR B |
| not both … and … | NAND | the alarm sounds unless both are safe → A NAND B |
| neither … nor … | NOR | neither window nor door is open → W NOR D |
1 S = 1 when a switch is on; D = 1 when a door is open. Write an expression for: the lamp is on when the switch is on and the door is not open.
2 Write an expression for: the buzzer sounds when neither P nor Q is 1.
3 How many gates do you draw for NOT (A OR B)?
- 1
X = S AND (NOT D) - 2
X = P NOR Q - 32: an OR gate, then a NOT gate (do not swap them for one NOR gate)
From an expression to a circuit and a truth table
An expression already tells you how to build its circuit, if you read it from the inside out. Draw one gate for each operator, starting inside the brackets. Then fill in the truth table one column at a time.
Draw it, one gate per operator
A NAND B and B NOR C.The circuit shows which gates; the truth table shows what they do for every input. Give each bracket its own column, so each step can be checked on its own.
Truth table with working columns
| A | B | C | P | Q | X |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 | 0 |
| 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 |
Fill it in column by column
- List A B C in binary counting order, 000 to 111: 2³ = 8 rows.
- Work out each bracket first, in its own column (P, Q).
- Then combine the working columns: X = P XOR Q.
- Use the P and Q from the same row; never mix rows.
Check contrasting rows
- A/B/C = 0/0/0: NAND gives P = 1 and NOR gives Q = 1, so XOR gives X = 0.
- A/B/C = 1/0/1: P = 1 and Q = 0, so X = 1.
- XOR gives 1 only when P and Q differ.
1 For X = (A AND B) OR (NOT C), how many gates does the circuit need?
2 Which gate gives the output X?
3 Complete the X column of its truth table, rows 000 to 111.
- 13: AND, NOT, OR
- 2OR
- 3X = 1 0 1 0 1 0 1 1 (work out A AND B and NOT C first, then OR them)
A condition that A is not 1 is true when A = 0. Write it as NOT A.
From a circuit to an expression
A circuit can look tangled from the inputs, but it has only one output, so start there. Read the circuit from the output backwards: write the last gate, then replace each of its inputs with the part of the circuit that feeds it, in brackets.
Each card names one gate, working from Y back towards the inputs, and writes the part of the expression that gate gives.
The gate that gives Y is OR, fed by P and Q.
An AND gate fed by A and NOT B.
A NOT gate fed by an XOR of B and C.
Put each wire's part in brackets in place of P and Q.
A truth table proves the expression describes the circuit. Fill P and Q for every row first; Y then needs only the OR gate.
Truth table from the circuit
| A | B | C | P | Q | Y |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 1 | 1 |
Label every wire
Write the value of each intermediate wire (P, Q) for each row before you work out the output. Brackets in the expression match the gates in the circuit.
Keep each gate
The NOT after the XOR stays as two gates: write NOT (B XOR C). B branches at the junction dot, so it appears twice in the expression.
Bracket the whole input to NOT
NOT (B XOR C) flips the XOR's output. (NOT B) XOR C puts the NOT on a different wire: a different circuit.
Check your answer
Count the gates in the circuit (5) and the operators in your expression (NOT, AND, XOR, NOT, OR = 5). They must match.
1 Write the expression for this circuit.
2 Find X when A = 0, B = 0 and C = 1.
3 How many of the 8 input rows give X = 1?
- 1
X = (A NOR B) AND (NOT C)(3 gates, 3 operators) - 20: A NOR B = 1, but NOT C = 0, so AND gives 0
- 31 row: A = 0, B = 0, C = 0
From a truth table to an expression and a circuit
Sometimes all you are given is what a circuit must do: its truth table. You can work backwards from it, from the output column to an expression, then from the expression to a circuit.
Write the expression from the truth table
1 · Check for a single gate
Compare the output column with the six gates. If it matches one, that gate is a correct answer.
2 · Otherwise, use the rows where X = 1
Write one term per row: AND the inputs together, using NOT for an input that is 0. Then join the terms with OR.
X is 1 in two rows, 00 and 11, and the column matches none of the six gates, so write one term for each shaded row.
| A | B | X |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
| Row with X = 1 | Term |
|---|---|
| A = 0, B = 0 | (NOT A) AND (NOT B) |
| A = 1, B = 1 | A AND B |
Draw the circuit from the expression
Each term becomes an AND gate, labelled in its own colour as in the table, and the OR gate joins the two.
Check it
Work out X for every row using your circuit. Every row must match. If a question gives you an expression or a circuit, keep its gates: do not redesign it.
Table 1: which single gate is it? Tables 2 and 3: write an expression for X.
1
| A | B | X |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
2
| A | B | X |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
3
| A | B | X |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
- 1XOR: 1 only when the inputs differ
- 2one row with X = 1 (A = 1, B = 0):
X = A AND (NOT B) - 3two rows with X = 1 (00 and 10):
X = ((NOT A) AND (NOT B)) OR (A AND (NOT B)). NOT B alone gives the same table: any expression that matches every row is correct.
Three-input truth tables
The method for two inputs works for three, with one catch. A row where X = 1 now has three inputs to join, and every gate takes only two, so each term needs two AND gates.
A three-input example
X is 1 in two rows, so there are two terms. Each one ANDs all three inputs, with a NOT on any input that is 0 in its row.
| A | B | C | X |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 0 |
Each highlighted row gives one term:
| Row with X = 1 | Term (two-input gates) |
|---|---|
| A = 0, B = 1, C = 1 | ((NOT A) AND B) AND C |
| A = 1, B = 1, C = 0 | (A AND B) AND (NOT C) |
Draw it with two-input gates
Each coloured label sits on the AND gate that finishes its term. Trace back from it to find the first AND gate and the NOT it needs.
Two AND gates per term
A row such as A = 0, B = 1, C = 1 needs two AND gates: ((NOT A) AND B) AND C. The OR gate then joins the two terms.
1 How many rows does a truth table with three inputs have?
2 Write the term for the row A = 1, B = 0, C = 1, using two-input gates.
3 X = 1 only in rows 001 and 111. Write an expression for X.
- 12³ = 8 rows, 000 to 111
- 2
(A AND (NOT B)) AND C - 3
X = (((NOT A) AND (NOT B)) AND C) OR ((A AND B) AND C)(7 gates: 2 NOT, 4 AND, 1 OR)
From a problem statement to logic
Real problems arrive as a description of a system, not as logic. Work from the defined input states (what 0 and 1 mean), not from one word alone. A greenhouse fan switches on in two ways: high humidity, or high temperature with the window closed.
1 · Write down what 0 and 1 mean for each input
| Input | 0 state | 1 state |
|---|---|---|
| T | temperature not too high | temperature too high |
| W | window closed | window open |
| H | humidity not high | humidity high |
2 · Turn each condition into logic, then join them
Each condition in the description becomes one bracket; the last row says how the brackets join.
| Condition that switches the fan on | Logic relationship |
|---|---|
| Temperature too high and window closed | T = 1 with W = 0: T AND (NOT W) |
| Humidity high | H = 1 independently of temperature and window |
| Either condition is sufficient, including both | Combine the two conditions with OR |
Play one situation through the circuit: T = 1, W = 0, H = 0. Each gate's output appears beside it, and the blue row of the truth table is the same situation.
Read the table
- H = 1 → the fan is on, whatever T and W are.
- H = 0 → the fan is on only when T = 1 and W = 0.
Truth table
| T | W | H | X |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
Blue row: the situation played in the circuit.
Check what 1 means before you use NOT
- Here W = 1 means open, so “window closed” is NOT W.
- If W = 1 had meant closed, you would use W itself, with no NOT.
1 An alarm X sounds when the system is armed and the door is open, or when the panic button is pressed. A = 1 means armed; D = 1 means the door is closed; P = 1 means the button is pressed. Write the expression.
2 Find X when A = 1, D = 1 and P = 0.
3 How many of the 8 rows give X = 1?
- 1
X = (A AND (NOT D)) OR P: the door is open when D = 0, so use NOT D - 20: the door is closed and the button is not pressed
- 35: the 4 rows with P = 1, plus A = 1, D = 0, P = 0