Digital Logic Explained

September 3, 2026 • 7 min read

Digital Logic Explained
Table of contents

Part of the series:Computers Explained

The CPU post treated the ALU and the control unit as given: boxes that add, compare, and orchestrate. This post opens those boxes. We will build upward from the humblest component, a switch, through the mathematics of true and false, the gates that embody it, the circuits that compute and remember, and finally the ladder that reaches back up to the processor.

The transistor: a switch, nothing more

At the bottom there is no Boolean logic, only physics. A transistor1 is an electrically controlled switch: a small voltage on one terminal decides whether current flows between the other two. On means current can flow; off means it is largely blocked.

Everything else in this post is a consequence of that one behavior plus a convention from the previous post: interpret a high voltage as 1 and a low voltage as 0. Billions of such switches, etched into silicon and wired together, become a machine that computes. You do not need the semiconductor physics to continue. Only the mental model of a switch being controlled billions of times per second matters.

Boolean logic: the math of true and false

Switches need a mathematics, and it is Boolean algebra2: a system with only two values, 0 (false) and 1 (true), and three fundamental operations:

  • AND (A · B): 1 only if both inputs are 1.
  • OR (A + B): 1 if at least one input is 1.
  • NOT (¬A): flips the value (¬0 = 1, ¬1 = 0).

Two derived operations appear so often they earned their own names: XOR (exclusive OR, 1 when the inputs differ) and the negated pair NAND (NOT AND) and NOR (NOT OR). NAND is special because any Boolean function can be built from NAND gates alone. NOR shares this property. Chip designers love that, because mastering one gate type means being able to build everything.

The gates: logic made physical

A logic gate3 is the physical embodiment of a Boolean operation: a handful of transistors wired so the output voltage follows the operation’s rule. Each gate is fully described by its truth table4: every input combination and the resulting output.

AND, OR, and NOT:

AND          OR           NOT
A B | Q      A B | Q      A | Q
0 0 | 0      0 0 | 0      0 | 1
0 1 | 0      0 1 | 1      1 | 0
1 0 | 0      1 0 | 1
1 1 | 1      1 1 | 1

XOR5, NAND, and NOR6:

XOR          NAND         NOR
A B | Q      A B | Q      A B | Q
0 0 | 0      0 0 | 1      0 0 | 1
0 1 | 1      0 1 | 1      0 1 | 0
1 0 | 1      1 0 | 1      1 0 | 0
1 1 | 0      1 1 | 0      1 1 | 0

Read XOR as “are they different?” and NAND as “not both.” Once you can read these tables, you have the basic vocabulary for reading digital circuits: gates wired together.

Combinational logic: turning gates into useful machines

A combinational circuit is a circuit whose output is purely a function of the current inputs. No memory, no feedback loops: same inputs, same output, every time.

Three circuits cover most of what the CPU does.

1. The adder: the math engine

Adds binary numbers. The machine never sees 2, only 0 and 1, so an adder works on binary representations, never on real or floating point numbers. It does the same “carry the one” addition you learned in school, one column at a time.

Example: 01 + 01 = 10.

  01  (1)
+ 01  (1)
----
  10  (2)

Right column: 1 + 1 does not fit in a bit, so write 0 and carry 1. Left column: 0 + 0 + 1 = 1.

Inside, the smallest adder is the half adder: it adds two bits, with sum A XOR B and carry A AND B. A full adder adds the carry-in as well, and chaining eight of them gives a ripple-carry adder7 that adds two bytes.

Real example: 2 + 3 becomes 010 + 011 = 101 (5). The same circuit increments the program counter to fetch the next instruction.

2. The multiplexer (mux): the selector switch

A multiplexer8 is a digital selector switch: it routes one of several inputs to a single output, chosen by the select lines. A 2-to-1 mux:

S | Q
0 | D0
1 | D1

Real example: result = s ? b : a is a mux in code. The CPU uses muxes to pick which register feeds the ALU, or which result to keep.

3. The decoder: the address router

A decoder9 takes an n-bit binary code and activates exactly one of its 2^n output lines. A 2-to-4 decoder:

A1 A0 | Y0 Y1 Y2 Y3
0  0  | 1  0  0  0
0  1  | 0  1  0  0
1  0  | 0  0  1  0
1  1  | 0  0  0  1

Real example: to write into register 2, the CPU sends 10 and only that register’s wire turns on.

Sequential logic: circuits that remember

A sequential circuit10 is a circuit whose output depends on both the current inputs and the previous state. To keep that state, the output is fed back into the input: a feedback loop.

Three components carry the state.

1. The flip-flop: one bit that stays put

A flip-flop11 is a 1-bit bistable storage element: it holds a 0 or a 1 even after the input goes away, and it only updates at the edge of the clock signal.

tick 1, D = 1         -> Q becomes 1 and holds 1
between ticks, D = *  -> Q still holds 1, whatever D does
tick 2, D = 0         -> Q becomes 0 and holds 0

Real example: a boolean flag like is_logged_in = true is a single flip-flop, holding its value while the CPU does other work.

2. The register: bits in formation

A register12 is an array of n flip-flops grouped together to store an n-bit binary word. Eight flip-flops sharing one clock is an 8-bit register.

store 5:  00000101 (each bit lives in one flip-flop)
tick:     all 8 bits are captured together
later:    00000101 is still there

Real example: when you write int a = 5, those eight bits sit in a register inside the CPU, the workbench where the processor keeps the values it is using right now. Add a mux to pick which register to read and a decoder to pick which one to write, and you get a register file.

3. The clock: everyone marches together

The clock signal13 is an oscillating square wave that synchronizes when state transitions happen across all flip-flops. It computes nothing: it only decides the moment everything updates.

Real example: if the clock ticks before the slowest adder has settled, a register captures the wrong value. That is why clock speed in gigahertz has a physical limit.

The big picture

The full ladder, bottom to top:

transistors
    ↓
logic gates
    ↓
circuits
    ↓
CPU

Transistors switch. Gates compute truth functions. Wiring gates together builds circuits: adders, multiplexers, and decoders compute without remembering, while registers remember, all synchronized by the clock. The ALU is just a circuit that combines arithmetic and logic. Add registers and control logic to it and you have a CPU, stepping through fetch-decode-execute on every clock edge.

We have now reached the processor: the next posts will move upward through memory, storage, and I/O, completing the picture of the machine before we leave hardware behind.

Footnotes

  1. Transistor - Wikipedia

  2. Boolean algebra - Wikipedia

  3. Logic gate - Wikipedia

  4. Truth table - Wikipedia

  5. XOR gate - Wikipedia

  6. NAND logic - Wikipedia

  7. Adder (electronics) - Wikipedia

  8. Multiplexer - Wikipedia

  9. Decoder - Wikipedia

  10. Sequential logic - Wikipedia

  11. Flip-flop (electronics) - Wikipedia

  12. Processor register - Wikipedia

  13. Clock signal - Wikipedia