๐Ÿ’ป Computer Science Guide

Logic Gates and Truth Tables

A complete guide to the six fundamental logic gates โ€” AND, OR, NOT, NAND, NOR and XOR โ€” with full truth tables, real-world analogies and KCSE worked examples.

โœ๏ธ By Mwalimu Ronny๐Ÿ“š Secondary & University Levelโฑ๏ธ 12 min read

What Are Logic Gates?

A logic gate is an electronic circuit that takes one or more binary inputs (each either 0 or 1) and produces a single binary output (either 0 or 1), based on a specific logical rule. Logic gates are the fundamental building blocks of all digital circuits โ€” from simple calculators to the processors inside your smartphone.

Every arithmetic operation your computer performs, every comparison it makes, and every decision in every program you run is ultimately carried out by combinations of millions of logic gates switching billions of times per second.

The behaviour of a logic gate is completely described by its truth table โ€” a table that lists every possible combination of inputs and the output that results from each combination.

Remember: In logic gates, 1 means TRUE (or HIGH voltage) and 0 means FALSE (or LOW voltage). These correspond directly to the binary digits you learned in the binary number system.

The Six Fundamental Logic Gates

You need to know six logic gates for KCSE Computer Studies. Each gate has a name, a symbol, a Boolean expression and a truth table.

AND Gate

Output is 1 only when ALL inputs are 1

Boolean expression: Y = A ยท B (or A AND B)

Real-world analogy: A door that opens only when BOTH keys are inserted simultaneously.

ABY = A AND B
000
010
100
111

OR Gate

Output is 1 when AT LEAST ONE input is 1

Boolean expression: Y = A + B (or A OR B)

Real-world analogy: A light that turns on if EITHER switch A or switch B (or both) is flipped.

ABY = A OR B
000
011
101
111

NOT Gate (Inverter)

Output is the OPPOSITE of the input

Boolean expression: Y = ฤ€ (or NOT A)

Real-world analogy: An alarm that sounds when a sensor does NOT detect someone โ€” it inverts the signal.

AY = NOT A
01
10

Note: The NOT gate has only ONE input, unlike the others.

NAND Gate

NOT AND โ€” opposite of the AND gate output

Boolean expression: Y = โ€พ(AยทB) (NOT of A AND B)

Key fact: NAND is called a "universal gate" โ€” you can build any other logic gate using only NAND gates.

ABY = NAND
001
011
101
110

NOR Gate

NOT OR โ€” opposite of the OR gate output

Boolean expression: Y = โ€พ(A+B) (NOT of A OR B)

Key fact: NOR is also a universal gate โ€” like NAND, you can build any circuit using only NOR gates.

ABY = NOR
001
010
100
110

XOR Gate (Exclusive OR)

Output is 1 when inputs are DIFFERENT

Boolean expression: Y = A โŠ• B

Real-world analogy: A staircase light controlled by two switches โ€” the light is on only when the two switches are in different positions.

ABY = XOR
000
011
101
110

How to Read a Logic Gate Question

KCSE questions typically give you a logic circuit diagram with gates connected together, provide specific input values, and ask you to determine the final output. Here is a systematic approach:

  1. Identify each gate in the circuit and its type (AND, OR, NOT, etc.).
  2. Start from the inputs on the left and work right toward the output.
  3. Calculate the output of each gate using its truth table.
  4. Feed that output as the input to the next gate.
  5. Continue until you reach the final output.

Worked Example 1 โ€” Combined Gates

A circuit has inputs A=1, B=0, C=1. Gate 1 is AND (inputs A, B). Gate 2 is OR (inputs: output of Gate 1, and C). Find the output.

Step 1: Gate 1 (AND): A=1, B=0 โ†’ 1 AND 0 = 0

Step 2: Gate 2 (OR): output of Gate 1 = 0, C = 1 โ†’ 0 OR 1 = 1

Final output: 1

Worked Example 2 โ€” Using De Morgan's Laws

Simplify: NOT(A AND B). According to De Morgan's first law, this equals NOT A OR NOT B.

If A=1, B=0: NOT(1 AND 0) = NOT(0) = 1

Verify with De Morgan: NOT A OR NOT B = NOT(1) OR NOT(0) = 0 OR 1 = 1 โœ“

De Morgan's Laws

De Morgan's laws are two essential rules for simplifying Boolean expressions involving NOT, AND and OR:

These laws are extremely useful for simplifying complex logic circuits and converting between gate types. They appear frequently in KCSE Paper 1 questions.

KCSE Tips for Logic Gates

โŠ• Practice Logic Gates

Test your knowledge with interactive truth table questions and SVG gate diagrams.

Play Logic Gates Game โ†’

Summary

There are six fundamental logic gates: AND (output 1 only if all inputs are 1), OR (output 1 if any input is 1), NOT (inverts a single input), NAND (inverse of AND), NOR (inverse of OR), and XOR (output 1 only when inputs differ). Each gate is completely described by its truth table. NAND and NOR are universal gates. De Morgan's laws link NAND to NOT-OR and NOR to NOT-AND. Logic gates are the building blocks of all digital circuits and all computer processors.