Logic gates

Computer Science · Boolean logic. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science topics

The idea

A logic gate is a small electronic circuit that takes binary inputs and gives one binary output. Each input and output is either 1 (on, true) or 0 (off, false). Computers are built from very large numbers of these gates.

You need six gates: NOT, AND, OR, NAND, NOR and XOR. The NOT gate has one input. The others have two inputs at this level. For each gate you must know its symbol, what it does in words, and its output for every possible input.

NAND and NOR are simply AND and OR with the output inverted. In a symbol, a small circle at the output means the output is inverted.

In simpler words

A logic gate is a tiny circuit. It takes inputs that are 1 or 0 and gives one output. There are six gates to learn: NOT, AND, OR, NAND, NOR and XOR. NOT flips its input. AND needs both inputs on. OR needs at least one. NAND and NOR are AND and OR flipped. XOR needs the inputs to be different.

An everyday comparison

An AND gate is like a bank vault that needs two keys turned at once. An OR gate is like a room with two doors, where either one lets you in. XOR is like a hallway light with two switches that is on only when the switches differ. The comparison stops working because gates work only with binary 1 and 0.

Rules to remember

Common mistake

Students confuse OR with XOR. With both inputs at 1, OR gives 1 but XOR gives 0. For NAND and NOR, work out AND or OR first and then invert the result.

In the exam

Draw each gate symbol accurately, adding a small circle for NOT, NAND and NOR. Describe each gate in words, for example NAND gives 0 only when both inputs are 1. Write the truth table with inputs in order 00, 01, 10, 11. For NAND and NOR, work out AND or OR first, then invert. Remember that XOR with 1, 1 gives 0.

Worked example

Inputs A = 1 and B = 0 are connected to a NAND gate and, separately, to a NOR gate. What is the output of each gate?

  1. NAND: first find A AND B = 1 AND 0 = 0, then invert it to get 1.
  2. NOR: first find A OR B = 1 OR 0 = 1, then invert it to get 0.

Answer: NAND output = 1, NOR output = 0

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

← Structured query language (SQL)Logic circuits and logic expressions →Take a Computer Science test