Logic gates are the physical switches everything else in a computer is built from. This page focuses on two things worth genuinely understanding: how simple gates combine into a circuit that actually adds binary numbers, and how to simplify a Boolean expression with proof at every step, not just a final answer to trust.
Section 2
The basic gates
Pick a gate and toggle its inputs. Watch which row of the truth table lights up to match.
AND→
0
Choose a gate
Exam tips
NAND and NOR are just AND/OR with the output inverted, one extra NOT on the end.
XOR outputs 1 only when the inputs differ, this is exactly what makes it useful for addition.
Section 3
Proof: NAND alone can build every other gate
This is why NAND is called a universal gate. You don't strictly need separate NOT, AND and OR gates at all, wiring NAND gates together in the right pattern reproduces every one of them exactly. This is a genuine reason real chips are built almost entirely from one repeated gate design.
AB
How each gate is built from NAND alone
Gate
Built from NAND as
NOT(A)
NAND(A, A)
AND(A,B)
NAND(NAND(A,B), NAND(A,B))
OR(A,B)
NAND(NAND(A,A), NAND(B,B))
NOT is just NAND fed the same input twice. AND is NAND's output inverted (using the NOT-from-NAND trick on itself). OR is built by inverting both inputs first, then NANDing those, which is exactly De Morgan's law in physical form.
Section 4
Building a real circuit: binary addition in hardware
Remember doing binary column addition by hand, writing the bit and carrying the 1? This is the actual circuit that does exactly that, built from nothing but two gates.
Half adder (adds two single bits)
A
B
→
0
SUM (XOR)
0
CARRY (AND)
Full adder (adds two bits plus a carry-in, so they can be chained)
Built from exactly two half adders (the circuit above, used twice) plus one OR gate to combine their two carry outputs.
A
B
Carry in
→
0
SUM
0
Carry out
Exam tips
Half adder: SUM = A XOR B, CARRY = A AND B. It only handles two bits with no incoming carry, so it can't be chained on its own.
Full adder: SUM = A XOR B XOR Cin, COUT = (A AND B) OR (Cin AND (A XOR B)). Chain several full adders together, each one's carry-out feeding the next one's carry-in, and you can add numbers of any size.
This is genuinely how addition happens in a real CPU's ALU, not a simplified analogy.
Section 5
Chaining full adders: a real 4-bit adder
Four full adders, wired so each one's carry-out feeds the next one's carry-in, exactly like the overflow work you've already covered, except this time it's genuinely happening in the circuit, not just described in words. Set two 4-bit numbers and watch the carry ripple through, right to left.
A (bits 8,4,2,1)
B (bits 8,4,2,1)
Exam tips
Carries ripple from the least significant bit (rightmost) to the most significant (leftmost), exactly the direction you were taught for binary addition by hand.
A final carry out of the leftmost full adder, with nowhere further to go, is precisely what overflow looks like in hardware: it's the same discarded bit from the overflow lesson, now visibly produced by a real chain of gates.
This "ripple" design is simple but has a real downside: bit 3's adder can't finish until bit 0, 1 and 2 have all rippled their carries through first, which is why faster (but more complex) adder designs exist in real CPUs.
Section 6
Boolean laws, verified live
Not just a table to memorise, toggle A, B and C and watch every law hold true for every combination you try. That's what makes these laws, laws, rather than a coincidence for one specific input.
ABC
Section 7
Simplifying with proof, not just an answer
Every step below is checked against a live truth table. If simplifying ever changed the actual logic, you'd see the table stop matching, it doesn't, at any step.
Truth table (unchanged throughout)
Section 8
De Morgan's law: the classic exam trap
It's tempting to think NOT(A AND B) is just NOT(A) AND NOT(B). It isn't. Toggle the inputs and watch both sides of each law stay identical, while the "wrong" version breaks.
AB
Section 9
Karnaugh maps: the same simplification, done visually
Section 7 simplified expressions with algebra, law by law. A Karnaugh map does the identical job by arranging every input combination on a grid where physically neighbouring cells differ by exactly one variable, so a valid group of 1s can always be described by dropping whichever variable changes across it. Click cells to build your own truth table, or load an example.
Simplified expression
–
Groups found
No groups yet.
How to read this
Groups must be rectangles of 1s sized a power of 2 (1, 2, 4, 8...). Groups can wrap around the grid's edges, the left and right edges are actually adjacent, and so are the top and bottom. Whichever variable stays constant across every cell in a group survives in that term, any variable that changes gets eliminated. A cell with a single coloured border belongs to one group. A cell showing small coloured dots in its corners instead belongs to more than one group at once, one dot per group, matching the colours of the group chips below.
Exam tips
Rows and columns are labelled in a special order (00, 01, 11, 10) called Gray code, not normal binary counting order, specifically so that every physically adjacent cell (including wrapping round the edges) differs by exactly one bit.
This grid is doing exactly the same job as the absorption law from Section 6: A.B + A.B' = A is precisely what a group of two adjacent 1s represents, B is the bit that changes across the group, so it's eliminated, leaving just A.
A cell can belong to more than one group at once if that helps produce a larger, simpler grouping, groups are allowed to overlap.
Section 10
D-type flip-flops: the CPU's actual memory cells
Every gate you've built so far responds instantly and continuously, change an input, the output updates immediately. A D-type flip-flop is different on purpose: it only ever looks at its D input at one precise moment, the instant the clock signal rises from 0 to 1, and then holds that value steady no matter what D does afterwards. This is the actual building block PC, MAR, MDR and ACC are made from.
Ready. Press Step to begin.
Controls
Right now
D = 0
CLK = 0
Q = 0
Exam tips
This specific behaviour is called edge-triggered. A falling edge (1 to 0) does nothing here, and D changing while the clock just sits at a steady 1 also does nothing, only the rising transition itself causes a capture.
Because Q holds its value between clock edges regardless of what D does, a D-type flip-flop is a genuine 1-bit memory cell, this is not a gate that computes something, it's a gate that remembers something.
Chain 4 together and you have a register
A CPU register like ACC isn't one special component, it's just several D-type flip-flops, one per bit, all sharing the same clock line. Load a 4-bit value and watch it only update on the shared clock pulse, exactly like ACC only changing at a specific point in the fetch-execute cycle.
Set the 4 D inputs below, then pulse the clock to load them all at once.
D inputs (bit 3 to bit 0)
Controls
Exam tips
Every flip-flop in the register shares the exact same clock signal, that's precisely why all 4 bits update together, in perfect step, rather than drifting out of sync with each other.
Back in the Fetch-Execute Cycle lesson, ACC only ever seemed to change at specific points, like right after the ALU finished, this is why: ACC is a register built from flip-flops just like this one, it genuinely cannot change except on a clock edge.