Purpose and use of logic gates
In one sentence: Logic gates are electronic switches that implement Boolean operators on binary voltage signals (
0and1), 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:
·denotesAND(A · B).+denotesOR(A + B).- An overline
ĀorNOT A(orNOT(...)around grouped terms) denotes negation. ⊕denotesXOR(A ⊕ B).⊙denotesXNOR(A ⊙ B).
Key words
| Term | Simple meaning |
|---|---|
| Logic gate | A digital circuit building block that takes one or more binary inputs and produces a single binary output using a fixed logical rule. |
| Boolean algebra | A two-valued mathematical system (0 and 1, or False and True) used to describe and simplify logical operations. |
| Transistor | A microscopic semiconductor switch whose control wire regulates electrical current flowing between source and drain terminals. |
| Truth table | A table listing every possible binary input combination alongside the resulting binary output. |
| Basic gates | The three foundational gates: AND, OR, and NOT. |
| Derived gates | Gates 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:
- Arithmetic and comparison: Inside the CPU's ALU (
A1.1.1), combinations ofXORandANDgates build binary adders and comparators. - Data routing and memory selection: Address decoders use
AND,OR, andNOTcombinations to enable the exact memory cell matching an address on the address bus. - Hardware control and safety interlocks: Embedded controllers check sensor flags (
doorClosed AND heatOK) directly in hardware without waiting for slower software checks. - Implementing programming conditionals: When you write
ifconditions withand,or, andnotin 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
A | B | X = A · B |
|---|---|---|
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
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
A | B | X = A + B |
|---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
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 = Ā(orNOT A)
A | X = NOT A |
|---|---|
0 | 1 |
1 | 0 |
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 overA · B)
A | B | X = NOT(A · B) |
|---|---|---|
0 | 0 | 1 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
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 overA + B)
A | B | X = NOT(A + B) |
|---|---|---|
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 0 |
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
A | B | X = A ⊕ B |
|---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
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 toNOT(A ⊕ B)or(A · B) + (NOT A · NOT B))
A | B | X = A ⊙ B |
|---|---|---|
0 | 0 | 1 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Summary comparison of all seven gates
| Gate | Inputs | Outputs 1 when… | Outputs 0 when… | Boolean notation |
|---|---|---|---|---|
AND | 2+ | All inputs are 1 | Any input is 0 | A · B |
OR | 2+ | At least one input is 1 | All inputs are 0 | A + B |
NOT | 1 | Input is 0 | Input is 1 | Ā or NOT A |
NAND | 2+ | At least one input is 0 | All inputs are 1 | NOT(A · B) |
NOR | 2+ | All inputs are 0 | At least one input is 1 | NOT(A + B) |
XOR | 2 | Inputs are different | Inputs are the same | A ⊕ B |
XNOR | 2 | Inputs are the same | Inputs are different | A ⊙ 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:
- Redundant backup alert (
NOR): An emergency shutdown alarm must fire (1) only if both power supplies have failed (A = 0andB = 0). Checking the summary table confirms thatNOR(NOT(A + B)) outputs1strictly on(0, 0)and0whenever at least one power supply is active. - 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 showsXOR(A ⊕ B) outputs1on(0, 1)and(1, 0), and0on(0, 0)and(1, 1). - High-level software link (
AND+NOT): Suppose firmware writesif sensorActive and not overrideSwitch:. Internally, the processor invertsoverrideSwitchwith aNOTgate and feeds that inverted result alongsidesensorActiveinto anANDgate. Only whensensorActive = 1andoverrideSwitch = 0(NOT 0 = 1) does1 · 1evaluate to1(True).
Check your understanding
- What physical component inside a microchip switches voltage states to build basic logic gates?
- How does the output of a 2-input
XORgate differ from that of a 2-inputORgate, and for which input row do they disagree? - State the output of a
NANDgate for(0, 0),(0, 1),(1, 0), and(1, 1). - Which single 2-input logic gate outputs
1if 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 (
0and1) across CPUs, memory circuits, hardware controllers, and conditional code execution. - Basic gates:
AND(both1),OR(at least one1), andNOT(inverts one input). - Derived gates:
NAND(NOT+AND,0only at1,1),NOR(NOT+OR,1only at0,0),XOR(inputs differ), andXNOR(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 (
A1toB2): 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.