Logic Gates: Truth Tables, NAND/NOR Universal Gates, Boolean Algebra

Every computer, calculator and mobile phone is built from logic gates: tiny circuits that take inputs of 0 or 1 and give an output of 0 or 1 according to a fixed rule. In entrance tests such as MDCAT, ECAT, NEET and JEE Main, gate questions are quick marks if you know the truth tables, can use NAND and NOR as building blocks, and can simplify a Boolean expression. This lesson covers all three and shows how to analyse a circuit of several gates step by step.

Asked in: MDCAT, NUMS, ECAT, NEET, JEE Main, FSc and Class 11-12 boards

Digital signals and Boolean variables

An analogue signal can take any value in a range, while a digital signal takes only two levels. In positive logic the high voltage (for example 5 V) is called 1 or TRUE and the low voltage (about 0 V) is called 0 or FALSE.

A Boolean variable such as A or B can only be 0 or 1. The rule that links the inputs of a gate to its output is shown in a truth table, which lists every possible input combination. A gate with n inputs has 2ⁿ rows: 4 rows for two inputs and 8 rows for three.

In this lesson AND is written as a dot (A·B), OR as a plus sign (A + B) and NOT as a prime or a word (A′ or NOT A). Remember that 1 + 1 = 1 in Boolean algebra: it means true OR true is true, not the number two.

The basic gates: NOT, AND and OR

The NOT gate (inverter) has one input and gives the opposite value: Y = A′. Its symbol is a triangle with a small circle (bubble) at the output; the bubble always means inversion.

The AND gate gives 1 only when all its inputs are 1: Y = A·B. Think of two switches in series: the lamp lights only if both are closed.

The OR gate gives 1 when at least one input is 1: Y = A + B. Think of two switches in parallel: closing either one lights the lamp. Its output is 0 only when every input is 0.

Derived gates: NAND, NOR, XOR and XNOR

A NAND gate is an AND followed by NOT, so its output is the reverse of AND: it is 0 only when all inputs are 1. A NOR gate is an OR followed by NOT, so it is 1 only when all inputs are 0. Their symbols are the AND and OR shapes with a bubble at the output.

The exclusive-OR (XOR) gate gives 1 when its two inputs are different: Y = A·B′ + A′·B. It is often called an odd-one detector or a difference detector. The XNOR gate is XOR followed by NOT; it gives 1 when the inputs are equal, so it works as an equality (coincidence) detector.

Two useful XOR facts: A XOR 0 = A and A XOR 1 = A′. So an XOR gate with one input held at 1 acts as a controlled inverter.

NAND and NOR as universal gates

NAND and NOR are called universal gates because any other gate, and therefore any digital circuit, can be built from just one of these types.

With NAND: joining both inputs gives NOT A. A NAND followed by a NAND-inverter gives AND (2 gates). Inverting each input and then NANDing gives OR, because NOT(A′·B′) = A + B (3 gates). XOR needs 4 NAND gates.

With NOR: joining both inputs gives NOT. A NOR followed by a NOR-inverter gives OR (2 gates). Inverting each input and then NORing gives AND, because NOT(A′ + B′) = A·B (3 gates). XOR needs 5 NOR gates.

Notice the pattern: NAND makes AND in 2 and OR in 3, while NOR makes OR in 2 and AND in 3.

Boolean algebra and De Morgan’s theorems

Identity and null laws: A + 0 = A, A + 1 = 1, A·1 = A, A·0 = 0. Idempotent laws: A + A = A and A·A = A. Complement laws: A + A′ = 1 and A·A′ = 0. Double negation: (A′)′ = A.

Absorption laws remove redundant terms: A + A·B = A and A·(A + B) = A. Another frequent result is A + A′·B = A + B. The distributive law works both ways in Boolean algebra: A·(B + C) = A·B + A·C and also A + B·C = (A + B)·(A + C).

De Morgan’s theorems convert between AND and OR: NOT(A + B) = A′·B′ and NOT(A·B) = A′ + B′. In words: break the bar and change the sign. These theorems are what make NAND and NOR universal.

Analysing combinations of gates

To analyse a circuit, label the output of every gate with an intermediate letter, write a truth table with a column for each, and fill it in from inputs to output. Then read off which input rows give Y = 1, or turn the table back into a simplified expression.

A half adder adds two single bits. Its sum output is A XOR B and its carry output is A·B. For 1 + 1 it gives sum 0 and carry 1, which is the binary number 10 (two).

Two shortcuts help in exam questions. A gate followed by a NOT gate becomes its opposite (AND becomes NAND, NOR becomes OR). Bubbles on both the inputs and the output of a gate convert AND to OR and OR to AND, by De Morgan’s theorems.

Solved examples

  1. Write the truth tables of the NAND and NOR gates for two inputs A and B.
    1. List the four input rows: 00, 01, 10, 11.
    2. AND gives 0, 0, 0, 1, so NAND gives 1, 1, 1, 0.
    3. OR gives 0, 1, 1, 1, so NOR gives 1, 0, 0, 0.
    Answer: NAND: 1, 1, 1, 0 and NOR: 1, 0, 0, 0 for inputs 00, 01, 10, 11
  2. Show how NAND gates can be used to make a NOT gate and an AND gate.
    1. Join both inputs of one NAND gate to A. The output is NOT(A·A) = NOT A, an inverter.
    2. For AND, feed A and B into a NAND to get NOT(A·B), then pass this through a NAND-inverter: NOT(NOT(A·B)) = A·B.
    3. So NOT needs one NAND gate and AND needs two. A truth table check: for 11 the first NAND gives 0 and the inverter gives 1; for every other row the first gives 1 and the inverter gives 0.
    Answer: NOT: one NAND with inputs joined. AND: two NAND gates in cascade
  3. Simplify Y = A·B + A·B′.
    1. Take A common: Y = A·(B + B′).
    2. By the complement law B + B′ = 1, so Y = A·1 = A.
    3. Check: for A = 1 one of the two terms is always 1, and for A = 0 both are 0.
    Answer: Y = A
  4. Ayesha wants to prove De Morgan’s theorem NOT(A + B) = A′·B′ using a truth table.
    1. Rows (A, B): 00, 01, 10, 11.
    2. A + B = 0, 1, 1, 1, so NOT(A + B) = 1, 0, 0, 0.
    3. A′ = 1, 1, 0, 0 and B′ = 1, 0, 1, 0, so A′·B′ = 1, 0, 0, 0.
    4. The two columns match in every row, so the identity holds.
    Answer: Both sides give 1, 0, 0, 0, so NOT(A + B) = A′·B′
  5. Inputs A and B are fed to an OR gate and also to a NAND gate. The two outputs are fed to an AND gate. Find the truth table and identify the circuit.
    1. Let P = A + B and Q = NOT(A·B). Then Y = P·Q.
    2. 00: P = 0, Q = 1, Y = 0. 01: P = 1, Q = 1, Y = 1.
    3. 10: P = 1, Q = 1, Y = 1. 11: P = 1, Q = 0, Y = 0.
    4. Y is 1 only when the inputs differ, so the circuit is an XOR gate.
    Answer: Y = 0, 1, 1, 0: the circuit behaves as an XOR gate
  6. Ravi has the expression Y = A′·B′·C + A′·B·C + A·B·C. Simplify it and list the inputs for which Y = 1.
    1. Combine the first two terms: A′·B′·C + A′·B·C = A′·C·(B′ + B) = A′·C.
    2. Now Y = A′·C + A·B·C = C·(A′ + A·B).
    3. Using A′ + A·B = A′ + B (the same form as X + X′·Y = X + Y), Y = C·(A′ + B).
    4. Y = 1 needs C = 1 and either A = 0 or B = 1: the inputs (A, B, C) = (0, 0, 1), (0, 1, 1) and (1, 1, 1), which are exactly the three original terms.
    Answer: Y = C·(A′ + B); Y = 1 for 001, 011 and 111

Exam shortcuts

Common mistakes

Practice MCQs

  1. A logic gate has three inputs. The number of rows in its complete truth table is:
    A) 3
    B) 6
    C) 8
    D) 9
    Answer: C) 8 — Each input can be 0 or 1, so three inputs give 2³ = 8 combinations. 6 is 2 × 3 and 9 is 3², both common slips with the formula 2ⁿ.
  2. A two-input gate gives an output of 1 only when its two inputs are different. The gate is:
    A) XOR
    B) OR
    C) XNOR
    D) NAND
    Answer: A) XOR — XOR gives 0, 1, 1, 0 for 00, 01, 10, 11, so it is 1 only for unequal inputs. OR also gives 1 for 11, XNOR does the opposite (1 for equal inputs), and NAND also gives 1 for 00.
  3. Both inputs of a NAND gate are joined together and connected to A. The gate now behaves as:
    A) An AND gate
    B) An OR gate
    C) A buffer whose output equals A
    D) A NOT gate
    Answer: D) A NOT gate — With both inputs equal to A, the output is NOT(A·A) = NOT A, so the gate is an inverter. It cannot act as AND or OR because it has only one independent input, and it inverts rather than copying A.
  4. The Boolean expression A + A·B simplifies to:
    A) A·B
    B) A
    C) B
    D) A + B
    Answer: B) A — Factor out A: A·(1 + B) = A·1 = A. This is the absorption law. Checking A = 0, B = 1 gives 0, which rules out B and A + B, and checking A = 1, B = 0 gives 1, which rules out A·B.
  5. By De Morgan’s theorem, NOT(A·B) is equal to:
    A) A′·B′
    B) A + B
    C) A′ + B′
    D) NOT(A + B)
    Answer: C) A′ + B′ — Break the bar and change AND to OR: NOT(A·B) = A′ + B′. A′·B′ is NOT(A + B), the NOR function, which is a different expression; A + B has no inversion at all.
  6. The output of a NOR gate is passed through a NOT gate. The combination is equivalent to:
    A) An AND gate
    B) An OR gate
    C) A NAND gate
    D) A NOR gate
    Answer: B) An OR gate — NOR is OR followed by NOT, and a second NOT cancels the first, leaving OR. A NAND would come from AND followed by NOT, and an AND would need inverted inputs, not an inverted output.
  7. One input of an XOR gate is permanently held at logic 1. Its output, in terms of the other input A, is:
    A) A
    B) 1
    C) 0
    D) A′
    Answer: D) A′ — XOR gives 1 when the inputs differ. With one input at 1, the output is 1 when A = 0 and 0 when A = 1, which is NOT A. Holding the input at 0 instead would give A.
  8. A half adder is given the inputs A = 1 and B = 1. Its outputs are:
    A) Sum 0, carry 1
    B) Sum 1, carry 0
    C) Sum 1, carry 1
    D) Sum 0, carry 0
    Answer: A) Sum 0, carry 1 — Sum = A XOR B = 0 and carry = A·B = 1, representing binary 10, which is two. Sum 1 with carry 0 is the result for inputs 01 or 10, and both outputs 1 would mean three.
  9. The minimum number of two-input NAND gates needed to make an OR gate is:
    A) 1
    B) 2
    C) 3
    D) 4
    Answer: C) 3 — Invert A and B with one NAND each, then NAND the results: NOT(A′·B′) = A + B, using 3 gates. Two NAND gates make an AND gate and four make an XOR gate.
  10. The minimum number of two-input NOR gates needed to make an OR gate is:
    A) 1
    B) 3
    C) 5
    D) 2
    Answer: D) 2 — A NOR gate gives NOT(A + B); passing it through a second NOR used as an inverter gives A + B. So 2 gates suffice. Three NOR gates are needed for AND, and five for XOR.
  11. The expression A + A′·B is equal to:
    A) A + B
    B) A
    C) A·B
    D) B
    Answer: A) A + B — Write A + A′·B = (A + A′)·(A + B) = 1·(A + B) = A + B. For A = 0, B = 1 the expression gives 1, which rules out A and A·B; for A = 1, B = 0 it gives 1, which rules out B.
  12. A circuit gives Y = (A + B)·C′. For which of these inputs (A, B, C) is Y = 1?
    A) (0, 0, 0)
    B) (0, 1, 0)
    C) (1, 0, 1)
    D) (1, 1, 1)
    Answer: B) (0, 1, 0) — Y = 1 needs A + B = 1 and C = 0. (0, 1, 0) satisfies both. (0, 0, 0) fails because A + B = 0, and the other two fail because C = 1 makes C′ = 0.
  13. A gate gives an output of 1 for inputs 00 and 11, and 0 for inputs 01 and 10. The gate is:
    A) XNOR
    B) XOR
    C) NOR
    D) AND
    Answer: A) XNOR — Output 1 when the inputs are equal is the XNOR (equality) gate, 1, 0, 0, 1. XOR is the exact opposite, NOR gives 1 only for 00, and AND gives 1 only for 11.
  14. Inputs A and B feed a NOR gate. Its output and the input A feed a second NOR gate, whose output is Y. Y equals 1 only when:
    A) A = 0 and B = 0
    B) A = 0 and B = 1
    C) A = 1 and B = 0
    D) A = 1 and B = 1
    Answer: B) A = 0 and B = 1 — Y = NOT(NOT(A + B) + A) = (A + B)·A′ = A′·B. This is 1 only for A = 0, B = 1. For 00 the first NOR gives 1, so the second gives 0; whenever A = 1 the second NOR gives 0.
  15. The Boolean expression (A + B)·(A + C) simplifies to:
    A) A·B + C
    B) A + B + C
    C) A·B·C
    D) A + B·C
    Answer: D) A + B·C — Expand: A·A + A·C + A·B + B·C = A + A·C + A·B + B·C = A + B·C, since A absorbs A·C and A·B. Checking A = 0, B = 1, C = 0 gives 0, which rules out A + B + C, and A = 1, B = 0, C = 0 gives 1, which rules out A·B + C and A·B·C.

Questions

Why are NAND and NOR gates called universal gates?

Because NOT, AND and OR can each be built from NAND gates alone, or from NOR gates alone, and every digital circuit can be made from NOT, AND and OR. Chip makers like this because a whole design can use a single type of gate.

What is the difference between OR and XOR?

They agree for 00, 01 and 10. For 11, OR gives 1 (at least one input is high) while XOR gives 0 (the inputs are not different). XOR is also the sum output of a half adder.

Is it better to simplify with algebra or with a truth table?

For two or three inputs a truth table is usually faster and safer in an exam. Algebra is useful when you are asked for a simplified expression, and the two methods should always agree.

What does the small circle on a gate symbol mean?

The bubble means inversion (NOT). A bubble at the output of an AND symbol makes it NAND, and at the output of an OR symbol makes it NOR. Bubbles at the inputs invert each input before the gate acts.