Skip to content

How do AND, OR, NOT and XOR gates work?

Switch the inputs and see each logic gate's output at once, with its symbol in both standard styles, its Boolean expression and truth table.

Gate and inputs

Symbol style

AND output

0

A = 1, B = 0 → AND gives 0

AND

Q = A · B

The output is 1 only when all inputs are 1.

Truth table of AND

A = 0, B = 0
0
A = 0, B = 1
0
A = 1, B = 0
0
A = 1, B = 1
1

Sponsored Links

All gates, ANSI shapes

  • AND

    Q = A · B

    What it means

    The output is 1 only when all inputs are 1.

  • OR

    Q = A + B

    What it means

    The output is 1 when at least one input is 1.

  • NOT

    Q = ¬A

    What it means

    The output is the opposite of the input: 1 becomes 0 and 0 becomes 1.

  • NAND

    Q = ¬(A · B)

    What it means

    NOT AND: the output is 0 only when all inputs are 1. Any other gate can be built from NAND gates alone.

  • NOR

    Q = ¬(A + B)

    What it means

    NOT OR: the output is 1 only when all inputs are 0. Like NAND, it can build every other gate.

  • XOR

    Q = A ⊕ B

    What it means

    Exclusive OR: with two inputs the output is 1 when they differ; with more, when an odd number of inputs are 1. It adds bits without the carry.

  • XNOR

    Q = ¬(A ⊕ B)

    What it means

    Exclusive NOR: with two inputs the output is 1 when they are equal; with more, when an even number of inputs are 1.

  • Buffer

    Q = A

    What it means

    The output equals the input. A buffer strengthens or delays a signal without changing it.

Switch the inputs and see each logic gate's output at once, with its symbol in both standard styles, its Boolean expression and truth table.

How to use

  1. Pick a gate: AND, OR, NOT, NAND, NOR, XOR, XNOR or buffer.
  2. Switch input A, and B for two-input gates, on (1) or off (0); the output changes at once.
  3. Choose ANSI shapes or IEC boxes to see the symbol used in American or in European and international drawings.

How it works

A logic gate is the smallest building block of digital electronics. It takes one or two inputs that are either 1 (on, high voltage) or 0 (off, low voltage) and gives one output. Its rule is a Boolean function, and its truth table lists the output for every combination of inputs. Two inputs have four combinations: 00, 01, 10 and 11.

AND is written A · B and gives 1 only for 11. OR is A + B and gives 1 unless both inputs are 0. NOT, written ¬A, flips its single input. XOR, A ⊕ B, gives 1 when the inputs differ. NAND, NOR and XNOR are AND, OR and XOR followed by NOT: the small circle on a symbol means the output is inverted. Example: 1 XOR 1 gives 0, and 1 NAND 1 gives 0, while 1 NAND 0 gives 1.

Two symbol styles are in use. The distinctive shapes, D-shaped AND and shield-shaped OR, come from IEEE Std 91 (ANSI) and are common in American and older drawings. The international standard IEC 60617-12 draws every gate as a box and writes its function inside: & for AND, ≥1 for OR (at least one input is 1), =1 for XOR (exactly one input is 1) and 1 for a buffer or NOT. The drawings here are our own renderings of both.

Real gates have more to them than the truth table: delay, voltage levels and how many inputs one output can drive. Gates with more than two inputs follow the same rule: an AND with three inputs gives 1 only when all three are 1.

Sponsored Links

Frequently asked questions

What is the difference between AND and OR?

AND gives 1 only when all inputs are 1. OR gives 1 when at least one input is 1.

Why are NAND and NOR called universal gates?

Any other gate, and so any digital circuit, can be built from NAND gates alone, or from NOR gates alone. NOT is a NAND with both inputs joined, for example.

What does the small circle on a gate symbol mean?

Inversion: the output (or the input it sits on) is flipped. That is the only difference between the AND and NAND symbols.

What does ≥1 mean in an IEC gate symbol?

That the output is 1 when at least one input is 1: an OR gate. =1 means exactly one input must be 1 (XOR) and & means all of them (AND).

What is XOR used for?

Adding binary digits (the sum bit of an adder), comparing bits, parity checks and simple encryption, since applying the same XOR twice gives back the original.

Which symbol style should I use?

Follow the drawings you work with. IEC boxes are the international standard and common in Europe; the ANSI shapes are common in the United States, in textbooks and in many data sheets.

More in Electronics & cabling

All 8 utilities in Electronics & cabling

Sponsored Links

Sponsored Links