IB Computer Science2027 syllabus
Level view
A1.2.3

Purpose and use of logic gates

SL & HL25 min readLesson

In one sentence: Logic gates are electronic switches that implement Boolean operators on binary voltage signals (0 and 1), forming the hardware foundation of every processor, memory controller, and digital decision circuit.

What you will learn

By the end of this lesson, you should be able to:

  • Explain the purpose of logic gates and why they sit at the heart of binary computing and computer systems.
  • Distinguish between basic gates (AND, OR, NOT) and derived gates (NAND, NOR, XOR, XNOR).
  • State the exact input-output behaviour, truth table, and Boolean algebra notation for all seven gates.
  • Connect hardware logic gates to conditional decisions in high-level programs.

Before you begin

Review Principal methods of representing data (A1.2.1) and How binary is used to store data (A1.2.2). Every wire entering or leaving a digital logic gate carries one binary state: low voltage (0 / False / Off) or high voltage (1 / True / On).

In Boolean algebra notation used throughout this lesson:

  • · denotes AND (A · B).
  • + denotes OR (A + B).
  • An overline Ā or NOT A (or NOT(...) around grouped terms) denotes negation.
  • ⊕ denotes XOR (A ⊕ B).
  • ⊙ denotes XNOR (A ⊙ B).

Key words

TermSimple meaning
Logic gateA digital circuit building block that takes one or more binary inputs and produces a single binary output using a fixed logical rule.
Boolean algebraA two-valued mathematical system (0 and 1, or False and True) used to describe and simplify logical operations.
TransistorA microscopic semiconductor switch whose control wire regulates electrical current flowing between source and drain terminals.
Truth tableA table listing every possible binary input combination alongside the resulting binary output.
Basic gatesThe three foundational gates: AND, OR, and NOT.
Derived gatesGates formed by combining basic gates: NAND, NOR, XOR, and XNOR.

The idea, step by step

Why computer systems rely on logic gates

Inside a computer, all data and instructions exist as binary voltage signals (0 and 1). To add two integers, compare numbers in the ALU, decode a machine instruction, or decide whether to grant memory access, the processor must transform input bit patterns into predictable output bit patterns. Logic gates are the physical components that perform those transformations.

At the transistor level, a semiconductor transistor behaves like a voltage-controlled switch: a control wire (gate) opens or blocks current between two terminals (called the source and drain). Applying a high voltage (1) to the control wire lets current flow; removing voltage (0) blocks flow. Putting a single transistor in series creates a simple buffer whose output mirrors its single input (0 stays 0, and 1 stays 1). Wiring two or more transistors in series, in parallel, or connected to ground yields the foundational logic gates, and grouping millions or billions of gates onto integrated circuits creates modern microprocessors, memory controllers, and embedded controllers.

In real computer systems, logic gates perform four core roles:

  1. Arithmetic and comparison: Inside the CPU's ALU (A1.1.1), combinations of XOR and AND gates build binary adders and comparators.
  2. Data routing and memory selection: Address decoders use AND, OR, and NOT combinations to enable the exact memory cell matching an address on the address bus.
  3. Hardware control and safety interlocks: Embedded controllers check sensor flags (doorClosed AND heatOK) directly in hardware without waiting for slower software checks.
  4. Implementing programming conditionals: When you write if conditions with and, or, and not in a language like Python or Java (B2.3.2), compiled machine instructions execute those tests using Boolean logic gates in the processor.

Basic logic gates (AND, OR, NOT)

The three basic gates provide conjunction, disjunction, and inversion:

1. AND gate

An AND gate takes two (or more) inputs and outputs 1 only when all inputs are 1. In hardware, two transistors wired in series produce AND behaviour because current reaches the output only if both switches conduct simultaneously.

  • Boolean expression: X = A · B
ABX = A · B
000
010
100
111

2. OR gate

An OR gate (inclusive OR) outputs 1 when at least one input is 1, including when both inputs are 1. Two transistors wired in parallel implement an OR gate because current bypasses an off switch through the active branch.

  • Boolean expression: X = A + B
ABX = A + B
000
011
101
111

3. NOT gate (inverter)

A NOT gate takes one input and outputs its opposite binary value (0 becomes 1; 1 becomes 0).

  • Boolean expression: X = Ā (or NOT A)
AX = NOT A
01
10

Derived (complex) logic gates (NAND, NOR, XOR, XNOR)

Combining basic gates creates four derived gates that simplify circuit design and express common conditions directly.

4. NAND gate (NOT AND)

A NAND gate is logically equivalent to an AND gate followed by a NOT gate. It outputs 0 only when both inputs are 1, and outputs 1 for every other input combination. (NAND is especially important in electronics because any Boolean circuit, including flash memory cells, can be built entirely out of NAND gates.)

  • Boolean expression: X = NOT(A · B) (written in textbooks with a continuous bar over A · B)
ABX = NOT(A · B)
001
011
101
110

5. NOR gate (NOT OR)

A NOR gate behaves like an OR gate followed by a NOT gate. It outputs 1 only when both inputs are 0, and 0 whenever at least one input is 1.

  • Boolean expression: X = NOT(A + B) (written with a continuous bar over A + B)
ABX = NOT(A + B)
001
010
100
110

6. XOR gate (exclusive OR)

An XOR gate outputs 1 only when the two inputs are different ((0, 1) or (1, 0)). Unlike inclusive OR, when both inputs are 1, XOR outputs 0. It can be built from basic gates as X = (A · NOT B) + (NOT A · B) (or (A + B) · NOT(A · B)). Hardware uses XOR to compute sum bits in binary addition and to check single-bit differences.

  • Boolean expression: X = A ⊕ B
ABX = A ⊕ B
000
011
101
110

7. XNOR gate (exclusive NOR)

An XNOR gate behaves like an XOR gate followed by a NOT gate. It outputs 1 only when both inputs are the same ((0, 0) or (1, 1)), making it a hardware equality detector for single bits.

  • Boolean expression: X = A ⊙ B (equivalent to NOT(A ⊕ B) or (A · B) + (NOT A · NOT B))
ABX = A ⊙ B
001
010
100
111

Summary comparison of all seven gates

GateInputsOutputs 1 when…Outputs 0 when…Boolean notation
AND2+All inputs are 1Any input is 0A · B
OR2+At least one input is 1All inputs are 0A + B
NOT1Input is 0Input is 1Ā or NOT A
NAND2+At least one input is 0All inputs are 1NOT(A · B)
NOR2+All inputs are 0At least one input is 1NOT(A + B)
XOR2Inputs are differentInputs are the sameA ⊕ B
XNOR2Inputs are the sameInputs are differentA ⊙ B

Worked example

A server rack monitors two redundant power supplies (A and B, where 1 means power OK and 0 means failed) and two cooling-fan signals:

  1. Redundant backup alert (NOR): An emergency shutdown alarm must fire (1) only if both power supplies have failed (A = 0 and B = 0). Checking the summary table confirms that NOR (NOT(A + B)) outputs 1 strictly on (0, 0) and 0 whenever at least one power supply is active.
  2. Mismatch detector (XOR): A technician dashboard wants a warning LED (1) whenever the two cooling sensors disagree: one reports healthy (1) while the other reports a fault (0), regardless of which one failed. Checking the summary table shows XOR (A ⊕ B) outputs 1 on (0, 1) and (1, 0), and 0 on (0, 0) and (1, 1).
  3. High-level software link (AND + NOT): Suppose firmware writes if sensorActive and not overrideSwitch:. Internally, the processor inverts overrideSwitch with a NOT gate and feeds that inverted result alongside sensorActive into an AND gate. Only when sensorActive = 1 and overrideSwitch = 0 (NOT 0 = 1) does 1 · 1 evaluate to 1 (True).

Check your understanding

  1. What physical component inside a microchip switches voltage states to build basic logic gates?
  2. How does the output of a 2-input XOR gate differ from that of a 2-input OR gate, and for which input row do they disagree?
  3. State the output of a NAND gate for (0, 0), (0, 1), (1, 0), and (1, 1).
  4. Which single 2-input logic gate outputs 1 if and only if its two binary inputs are identical?

Common mix-up

It is easy to think: NOR means "neither input is both 1" (outputting 0 only on (1, 1)), or OR outputs 0 when both inputs are 1.

Instead, remember: Inclusive OR outputs 1 on (1, 1), whereas XOR (exclusive OR) outputs 0 when both inputs match as (1, 1). NOR inverts OR, so it outputs 1 only when both inputs are 0 ((0, 0)), while NAND inverts AND and outputs 0 only when both inputs are 1 ((1, 1)).

Quick recap

  • Logic gates turn transistor switches into deterministic binary operations (0 and 1) across CPUs, memory circuits, hardware controllers, and conditional code execution.
  • Basic gates: AND (both 1), OR (at least one 1), and NOT (inverts one input).
  • Derived gates: NAND (NOT + AND, 0 only at 1,1), NOR (NOT + OR, 1 only at 0,0), XOR (inputs differ), and XNOR (inputs match).
  • Hardware logic gates directly mirror the Boolean operators (AND, OR, NOT) evaluated in programming selection and loop conditions.

Textbook reading

  • Computer Science (Baumgarten, Ganea, Turland, 2025), A1 Computer fundamentals > A1.2 Data representation and computer logic > A1.2.3 Purpose and use of logic gates, Book pp. 51–55 (PDF pp. 61–65).
  • Read these pages to reinforce the lesson, including transistor-level switch diagrams; this original explanation does not replace the textbook.

Sources and further learning

  • IB Computer Science Guide (first assessment 2027), A1.2.3: Describe the purpose and use of logic gates (Guide p. 29; PDF p. 35), and Theme A linking question (A1 to B2): Boolean logic gates and conditional statements.
  • Computer Science (Baumgarten, Ganea, Turland, 2025), A1.2.3 Purpose and use of logic gates, Book pp. 51–55 (PDF pp. 61–65). All worked examples and comparison tables above are original.
Check your understanding5 questions · 8 marks · 10 min
Take the lesson check
Something not right?