Daylila
How computers actually work

Lesson 4 of 13

The logic gate: a switch that decides

Explain how a transistor is a switch other switches control, and how gates (AND, OR, NOT) turn inputs into one decided output — the atom of all computation.

01 · Learn · the idea

A porch light that turns itself on when it gets dark, but only if someone’s home. A thermostat that fires the heating when the room drops below your number. These feel like small acts of judgement — the device looking at the world and deciding. But there’s no judgement anywhere inside. There’s a tiny arrangement of switches following one fixed rule, and that arrangement is the single most important building block in the whole machine. It’s called a logic gate, and once you’ve built one in your head, you’ve built the atom that everything else is made from.

So far our switches have been dumb storage — sitting on or off, holding a bit. This lesson is where switches start to do something.

A switch that another switch can flip

Back in lesson one, you flipped a light switch with your finger. The whole magic of a computer is this: a finger is too slow and too few. So engineers built a switch you flip not with a finger but with electricity from another wire. Send current down the control wire and the switch closes; cut the current and it opens. It’s called a transistor, and that one idea is the hinge the entire digital age swings on.

Read that again, because it’s the leap. A transistor is a switch that another switch can flip. So one part of the machine can control another part, with no hands involved. Chain them up and the machine runs itself — switches throwing switches throwing switches, billions of them, a few billion times a second. A modern chip holds tens of billions of these tiny electric switches. They are too small to see and they never get tired.

A gate takes inputs and decides one output

Now wire a handful of transistors together in a particular pattern, and something new appears. You get a little box with one or two input wires coming in — each carrying a bit, on or off — and one output wire going out, also on or off. The box looks at its inputs and sets its output by a fixed, unchanging rule. That box is a logic gate.

It has no memory, no mood, no choice. Same inputs in, same output out, every single time. The “decision” is baked into how the transistors are arranged. There are only a few basic rules worth knowing, and three of them do almost all the work.

The three rules: AND, OR, NOT

AND — output is on only if both inputs are on. On and on gives on. Any off gives off. Think of two switches in a row on the same wire: the current only reaches the end if both are closed.

OR — output is on if either input is on. On or on, doesn’t matter which — on. Only both-off gives off. Think of two switches side by side, two parallel paths: current gets through if at least one is open.

NOT — the odd one out: a single input, and it simply flips it. On becomes off, off becomes on. It’s the gate that says “the opposite of whatever you gave me.”

We can write each rule as a small table — a truth table — listing every possible input and the output it produces. AND has four rows (off-off, off-on, on-off, on-on); only the last gives an on. You’ll toggle through every one of those rows in the lab in a moment, so don’t worry about memorising them — feel them.

A worked example: the porch light

Let’s wire that porch light properly. We want it to come on only when it’s dark AND someone is home. Two sensors feed two input wires:

  • A light sensor: on when it’s dark, off in daylight.
  • A motion-and-presence sensor: on when someone’s home, off when the house is empty.

Run both into a single AND gate. The gate’s output drives the bulb. Now walk all four situations the world can throw at it:

  • Daytime, house empty → dark sensor off, home sensor off → AND says off. Bulb dark. Correct: nobody to light, and it’s bright anyway.
  • Daytime, someone home → dark off, home on → AND says off. Bulb dark. Correct: no point burning the porch light in sunshine.
  • Night, house empty → dark on, home off → AND says off. Bulb dark. This is the case a plain dark-sensor would get wrong — it’d light an empty house all night. The AND gate holds it dark.
  • Night, someone home → dark on, home on → AND says on. Bulb lights. The one case we wanted.

One bulb, lit in exactly one of four situations, and we never wrote a line of “if”. We just picked the gate whose rule matches the decision. Swap the AND for an OR and the light would come on if it were dark or someone were home — a different rule, a different porch. The gate you choose is the logic.

The cleverness is in the arrangement

Here is the whole tower in one sentence: every decision a computer makes, and every sum it works out, is millions of these dumb yes/no rules wired together. The next lesson takes a fistful of AND, OR and NOT gates and builds something that genuinely adds numbers — arithmetic, out of nothing but switches that say on or off.

Sit for a second with how little is down here. Not one gate in the machine understands anything. Each does the same blunt thing the porch light does — looks at one or two bits and obeys a rule it cannot change. The intelligence you feel when the device answers you isn’t in any gate, the way the noise of a crowd isn’t in any one voice. It lives only in the arrangement — which gate feeds which, layer on layer, all the way up to the screen in your hand. You’re looking at the atom now. Everything else in this course is just how they’re stacked.

02 · Try · the lab

03 · Check · quick quiz

1. What is the one idea that makes a transistor more powerful than the light switch you flip with a finger?

  • It is a switch that another wire's electricity can flip, so the machine can control itself
  • It can sit at ten different voltage levels instead of two
  • It remembers the last bit it was given even after the power is cut
  • It is much larger, so it carries more current
Answer

It is a switch that another wire's electricity can flip, so the machine can control itself — A transistor is a switch flipped by electricity from a control wire, not a finger. That lets one part of the machine throw switches in another part — so it runs itself, billions of times a second, no hands involved.

2. An AND gate's two inputs are: A on, B off. What is its output?

  • On — at least one input is on
  • Off — AND lights only when both inputs are on
  • On — A is on, and A decides
  • It depends on which input was switched first
Answer

Off — AND lights only when both inputs are on — AND outputs on only when both inputs are on. With B off, the rule fails, so the output is off. (The 'either is enough' rule is OR, not AND — and a gate has no memory of order; same inputs always give the same output.)

3. You want a porch light that comes on if it is dark OR someone is home — either reason is enough. Which gate wires the two sensors to the bulb?

  • An AND gate
  • A NOT gate
  • An OR gate
  • No single gate can do this
Answer

An OR gate — 'Either reason is enough' is exactly the OR rule: output on if either input is on. An AND gate would need both at once. The gate you choose is the logic — swap AND for OR and the same two sensors give a different porch.

4. A device answers your questions and feels almost like it is thinking. Where does that apparent intelligence actually live?

  • Inside the cleverest gate, which oversees the others
  • In no single gate — only in how millions of dumb gates are arranged, layer on layer
  • In a special memory chip that stores its decisions
  • In the speed of the electricity, which is near the speed of light
Answer

In no single gate — only in how millions of dumb gates are arranged, layer on layer — Not one gate understands anything; each just obeys a fixed rule on one or two bits. The intelligence is in the arrangement — which gate feeds which, stacked up — the way a crowd's roar is in no single voice.