Electronics Design AU
Digital

What Are Logic Gates and How Do They Work?

Last updated 28 June 2026 · 8 min read

Direct Answer

A logic gate is an electronic circuit that implements a Boolean function: it takes one or more binary inputs (high = 1, low = 0) and produces a single binary output. The six fundamental gates are AND (output is 1 only if all inputs are 1), OR (output is 1 if any input is 1), NOT (output is the inverse of the input), NAND (NOT-AND: output is 0 only if all inputs are 1), NOR (NOT-OR: output is 0 if any input is 1), and XOR (output is 1 if inputs differ). NAND and NOR are universal gates — any logic function can be built from NAND gates alone or NOR gates alone. In CMOS technology, NAND and NOR gates are cheaper to build than AND and OR (which require an additional inverter stage), which is why NAND is the dominant building block in real digital design.

Detailed Explanation

Every digital system — microcontrollers, FPGAs, CPUs, memory arrays — is ultimately built from combinations of a handful of fundamental building blocks: logic gates. Each gate implements one Boolean function, and by chaining gates together any digital behaviour can be expressed.

The Six Fundamental Gates

AND gate

ABA AND B
000
010
100
111

Output is 1 (high) only when all inputs are 1. In Boolean algebra: Y = A · B (the dot denotes AND; often written just AB).

OR gate

ABA OR B
000
011
101
111

Output is 1 when any input is 1. Boolean: Y = A + B (the plus denotes OR).

NOT gate (inverter)

ANOT A
01
10

Single-input gate; output is always the complement of the input. Boolean: Y = Ā (A with a bar).

NAND gate (NOT-AND)

ABA NAND B
001
011
101
110

Output is 0 only when all inputs are 1 — the complement of AND. Boolean: Y = AB̄. NAND is a universal gate: any logic function can be built from NAND gates alone.

NOR gate (NOT-OR)

ABA NOR B
001
010
100
110

Output is 1 only when all inputs are 0 — the complement of OR. Boolean: Y = A + B̄. NOR is also a universal gate.

XOR gate (exclusive OR)

ABA XOR B
000
011
101
110

Output is 1 when inputs differ — when exactly one input is 1. Boolean: Y = A ⊕ B. XOR is widely used for parity generation/checking, binary addition (half-adder), and comparison circuits.

The complement of XOR is XNOR (exclusive NOR): output is 1 when inputs are equal: Y = A ⊙ B. XNOR is used in equality comparators and LFSR (linear feedback shift register) implementations.

CMOS Implementation

In modern digital circuits, logic gates are implemented in CMOS (Complementary Metal-Oxide-Semiconductor) technology. Every CMOS gate uses two complementary transistor networks:

  • Pull-up network (PMOS transistors): connects the output to the supply voltage (VDD) when the output should be logic high.
  • Pull-down network (NMOS transistors): connects the output to ground (GND) when the output should be logic low.

A NAND gate (the most natural CMOS primitive):

  • Pull-up: two PMOS transistors in parallel — if A=0 OR B=0, the output is pulled to VDD.
  • Pull-down: two NMOS transistors in series — only if A=1 AND B=1, the output is pulled to GND.

An AND gate requires a NAND followed by an inverter — an extra transistor stage that adds propagation delay. This is why NAND is preferred in practice: it is both the natural CMOS implementation and a universal gate.

Similarly, NOR is the natural CMOS implementation of the OR function:

  • Pull-up: two PMOS in series.
  • Pull-down: two NMOS in parallel.

OR requires NOR + inverter.

Boolean Algebra: Simplifying Logic

Boolean algebra provides rules for simplifying logic expressions before implementing them in gates. Key laws:

IdentityLaw
A + 0 = AOR identity
A · 1 = AAND identity
A + A = AOR idempotent
A · A = AAND idempotent
A + Ā = 1OR complement
A · Ā = 0AND complement
A + B = B + ACommutative
A(B + C) = AB + ACDistributive
NOT(A AND B) = NOT(A) OR NOT(B)De Morgan's
NOT(A OR B) = NOT(A) AND NOT(B)De Morgan's

De Morgan's theorems are particularly important: they explain how NAND gates can replace AND + NOT, and how NOR gates can replace OR + NOT. They also appear whenever active-low signals are used in hardware design.

Example simplification: Suppose a circuit needs Y = AB + AC. Factoring: Y = A(B + C) — reduces from three gates (two ANDs, one OR) to two (one AND, one OR).

Universal Gates: NAND-Only Logic

Any logic function can be expressed using only NAND gates. This matters because it means a chip manufacturer can build one type of gate cell and implement any digital function from it.

  • NOT from NAND: connect both inputs of a 2-input NAND to the same signal → NOT
  • AND from NAND: NAND followed by NOT (= NAND followed by NAND-as-NOT)
  • OR from NAND: by De Morgan's, OR(A,B) = NAND(NOT(A), NOT(B))

Similarly, NOR is also universal — any function can be built from NOR gates alone. XOR is not universal by itself.

In real FPGA design, LUTs (Look-Up Tables) generalise the concept of universal gates: a 4-input LUT can implement any 4-input Boolean function, making it effectively a configurable universal logic element. See what is an FPGA for how LUTs work.

Logic Families and Voltage Levels

Gates are manufactured in various logic families with different voltage levels and drive strengths:

  • 5 V CMOS (4000 series): classic CMOS, slow but wide supply range.
  • 5 V TTL (7400 series): bipolar transistor logic, different switching thresholds than CMOS.
  • 3.3 V LVCMOS: modern MCU and FPGA I/O standard.
  • 1.8 V / 1.2 V CMOS: found in modern SoCs and DDR interfaces.

When connecting devices from different logic families, check that the output's logic high voltage (V_OH) exceeds the receiver's minimum high threshold (V_IH), and that the receiver's absolute maximum input voltage is not exceeded by the driver. See the digital topic hub for more on logic family compatibility.

Design Considerations

  • Fan-out matters. Each gate output can drive only a limited number of gate inputs (limited by its drive current). Exceeding the specified fan-out causes the output voltage to not fully reach the logic thresholds. Add a buffer gate if driving many loads.
  • Propagation delay accumulates. A chain of N gates has a propagation delay of N × t_pd (approximately). The maximum clock frequency in a synchronous circuit is limited by the longest combinational path through gates between flip-flops. Minimise this critical path by reducing gate count or using faster logic families.
  • Glitches in combinational logic. When multiple inputs change simultaneously, intermediate states cause momentary incorrect outputs (hazards or glitches). These are usually harmless in combinational-only circuits but can cause false register captures in sequential circuits. Use synchronous design practices to avoid glitch-sensitive behaviour.

Common Mistakes

  • Leaving unused gate inputs floating. An unconnected CMOS input floats at an indeterminate voltage, drawing excessive current and producing unpredictable outputs. Tie unused AND gate inputs to VDD (1), OR gate inputs to GND (0), or use a standard logic IC with only the inputs needed.
  • Mixing logic family voltage levels without level translation. Connecting a 5 V output to a 3.3 V input can exceed the absolute maximum input voltage rating and damage the receiving device. Always check both V_OH of the driver and V_IH_max of the receiver before direct connection.
  • Implementing XOR with NAND/NOR without timing analysis. The NAND-based XOR implementation uses a feedback path with different propagation delays; the output can glitch. For timing-critical paths, use a dedicated XOR gate or confirm the synthesis tool handles hazard elimination.
  • Treating NAND/NOR as equivalent to AND/OR in timing estimates. NAND and NOR gates are faster than AND and OR in CMOS — AND/OR require an extra inverter. Timing estimates based on AND/OR gate counts underestimate the actual critical path if the implementation uses AND/OR. Use synthesis tool timing reports, not manual gate counts, for timing analysis.

Frequently Asked Questions

Why are NAND gates preferred over AND gates in real digital design?
NAND is inherently easier to build in CMOS: a NAND gate consists of two NMOS transistors in series (pull-down) and two PMOS transistors in parallel (pull-up), giving a naturally inverted output. An AND gate requires an additional NOT stage (an inverter) to uninvert the NAND output, making it slower and using more transistors. Since NAND gates are universal — any logic function can be implemented from NAND gates alone — most standard cell libraries and FPGAs optimise for NAND-based logic. When synthesising HDL, tools automatically convert AND/OR logic to NAND/NOR equivalent implementations for efficiency.
What is De Morgan's theorem and why does it matter?
De Morgan's theorems describe how to transform between AND/OR and NAND/NOR forms: NOT(A AND B) = NOT(A) OR NOT(B), and NOT(A OR B) = NOT(A) AND NOT(B). In practice: (1) a NAND gate with inverted inputs behaves like an OR gate; (2) a NOR gate with inverted inputs behaves like an AND gate. This is used both in manual logic simplification and by synthesis tools to replace AND/OR logic with the NAND/NOR primitives that CMOS hardware implements natively. Understanding De Morgan's is also essential when interpreting active-low signals in hardware schematics, where a line like /RESET means 'NOT RESET' and its logic follows De Morgan's rules.
Can logic gates be made to accept more than two inputs?
Yes. AND, OR, NAND, NOR, and XNOR gates can have any number of inputs in theory; in practice 2-, 3-, and 4-input gates are most common in standard cell libraries. An N-input AND gate outputs 1 only if all N inputs are 1; an N-input OR gate outputs 1 if any of the N inputs is 1. XOR with more than 2 inputs is defined as an odd-parity function: output is 1 if an odd number of inputs are 1. High-fanin gates (many inputs) have larger delay and worse drive strength than chains of 2-input gates, so synthesis tools automatically balance gate count against delay.

References

Related Questions

Related Forum Discussions