Skip to content
BetterDL

Logic gate

Also called: logic gates, digital logic gate, basic logic gates

A small digital circuit that takes one or more binary inputs and produces one binary output by a fixed rule, such as AND, OR or NOT.

A logic gate is the smallest building block of digital hardware. It watches its input wires, each carrying a 0 or a 1, and drives its output wire to 0 or 1 according to one fixed rule. Change the inputs and the output follows almost instantly.

There are seven gates you meet in every course:

  • NOT: flips its single input.
  • AND: 1 only when every input is 1.
  • OR: 1 when at least one input is 1.
  • NAND and NOR: AND and OR with the output inverted.
  • XOR: 1 when the inputs differ.
  • XNOR: 1 when the inputs match.

Each gate can be described three equivalent ways: a symbol for drawing circuits, a boolean expression for writing it down, and a truth table that lists the output for every input combination. A gate with n inputs has 2ⁿ rows in its table.

Why do gates matter? Every digital system, from a calculator to a processor, is gates wired together. Adders, multiplexers, memory cells and control logic are all gate networks. Inside a chip each gate is a handful of transistors acting as switches, but for logic design you can treat a gate as a black box that obeys its truth table.

Two of the seven, NAND and NOR, are universal: either one alone can build every other gate.

00001101
01011010
10011010
11110001

Worked example

Example

One input row through every gate

Take A = 1 and B = 0. Work out what each basic gate outputs for this single row.

  1. 1.

    NOT A: A is 1, so the output is 0.

  2. 2.

    AND: not every input is 1 (B is 0), so 0.

  3. 3.

    OR: at least one input is 1, so 1.

  4. 4.

    NAND: the AND gave 0, inverted gives 1.

  5. 5.

    NOR: the OR gave 1, inverted gives 0.

  6. 6.

    XOR: the inputs differ, so 1.

  7. 7.

    XNOR: the inputs differ, so 0.

  8. 8.

    Compare with row 10 of the table above: every value matches.

Common mistakes

  • Reading + as arithmetic. In logic is OR, so 1 + 1 = 1, not 2.

  • Naming a gate from its body alone. A bubble on the output changes AND to NAND, OR to NOR and XOR to XNOR.

  • Assuming a gate's rule changes with more inputs. A 3-input AND is still 1 only when all inputs are 1.

Practice Logic gate

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Logic gate is taught in Logic Gates.