How a Relay Works: The Click That Built Modern Computing
Right now, as you read this, something inside your device is flipping switches. Billions of them, billions of times a second, with no moving parts and no sound. But the very first switches that computed anything did have moving parts, and they did make a sound — a sharp, satisfying click.
That click is where computing begins. Before the microchip, before the transistor, before the vacuum tube, there was the relay: a switch that electricity could throw all by itself. Learn how this one tiny device works, and you hold the seed of everything else — logic gates, arithmetic, memory, and eventually a working computer.
This is the first stop in a hands-on series we’re calling Building a Computer from Relays. It’s deeply inspired by Charles Petzold’s masterpiece CODE: The Hidden Language of Computer Hardware and Software — but instead of just reading about these circuits, you’ll toggle them live in your browser as we go. Think of it as CODE, made playable.
Let’s start at the very bottom: a single relay.
The problem that invented the relay
Our story opens in the 1830s, decades before anyone dreamed of a computer, with a very practical headache: how do you send a signal down a really long wire?
The electric telegraph could fire a pulse of current through a wire to click an electromagnet at the far end — dot, dot, dash. But electricity leaks. Push a signal down enough miles of wire and it fades into a whisper too weak to do anything useful. Early telegraph lines hit a wall at a few dozen miles.
The fix was beautifully simple. The American scientist Joseph Henry, a pioneer of the electromagnet, demonstrated the key idea: use the weak, far-away signal not to do the work, but to throw a switch — and let that switch connect a fresh, local battery to carry the signal onward, strong again.
That switch was the relay. The name says exactly what it does: it relays the message, like a runner handing off a baton. A tired, faint current arrives, trips a switch, and a brand-new full-strength current carries on. Telegraph operators could now chain relays down the line and span a continent.
Nobody in 1840 was thinking about logic or computers. They just wanted their dots and dashes to reach the next town. But hidden inside that practical little device was an idea that would eventually run the world: a switch controlled by electricity instead of by a human finger. Hold onto that — it’s the whole trick.
How a relay actually works, piece by piece
A relay looks like magic the first time you see one snap to life, but it’s pure first-principles physics. There are just three moving ideas.
1. The electromagnet (the coil). Wind a coil of wire around an iron core and run current through it, and you get a temporary magnet. Current on → magnetic. Current off → not magnetic. This is the relay’s “muscle,” and it’s controlled entirely by electricity.
2. The armature (the lever). Hovering just above the electromagnet sits a small iron lever, held back by a spring. When the coil energizes, its magnetic pull overcomes the spring and yanks the armature down. Cut the current and the spring snaps it right back. That snap is the click you hear.
3. The contacts (the switch). The armature carries a metal contact. As it moves, that contact either bridges or breaks a connection in a second, completely separate circuit. One wire’s current decides whether another wire’s current can flow.
Put them in sequence and the whole device reads like a tiny machine:
Current flows in the coil → the electromagnet pulls the armature → the armature moves the contact → a separate circuit switches on or off.
Energize the coil, and click — the output circuit closes and a lamp lights. Release it, and click — the lamp goes dark. A switch you never touch, thrown by electricity alone.
Normally open, normally closed: the relay’s two personalities
Here’s the detail that turns a relay from a curiosity into a logic device — and the part the engineers in the room have been waiting for.
A relay can be wired two ways:
- Normally open (NO): at rest, the contact is open and the output is off. Energize the coil and it closes. Coil on → output on. This relay simply passes its input along: a buffer.
- Normally closed (NC): at rest, the contact is closed and the output is on. Energize the coil and it opens. Coil on → output off. This relay inverts its input: a NOT.
So a single relay, depending on which contact you tap, is either a buffer or an inverter. We can write that as a one-input, one-output truth table — the first of many you’ll meet in this series:
| Coil (input) | NO contact → lamp | NC contact → lamp |
|---|---|---|
| 0 (off) | 0 (off) | 1 (on) |
| 1 (on) | 1 (on) | 0 (off) |
Two columns, two opposite behaviors, from one humble device. The fact that a relay can invert a signal — turn an ON into an OFF — is not a footnote. It’s the spark that makes real logic, and eventually decision-making, possible.
Toggle one yourself
Reading about a click is one thing. Throwing the switch is another. Below is a real, simulated relay, running a genuine DC circuit — not an animation, but an actual electromechanical simulation right inside this page.
Flip the knife switch to send current through the coil. Watch the armature get pulled down, watch the contact close, and watch the lamp light. Turn your sound on to hear the authentic relay click on every transition.
Try this while you play:
- Flip it slowly. Notice there’s a tiny delay between energizing the coil and the lamp lighting. That’s the armature physically traveling — a real, mechanical moment in time. Hold onto that delay; later in this series it becomes the heartbeat of clocks and memory.
- Listen. One click to pull in, one click to release. Every click is one bit of the world changing state.
- Imagine a thousand of them. That sound, multiplied across a roomful of relays, is exactly what the first computers sounded like as they thought.
Why a relay is the atom of computing
Step back and notice what just happened. The coil’s current controlled the contact’s current. One circuit threw a switch in another circuit.
That’s the property that changes everything, because it means relays can be connected to each other. The output of one relay can be the input — the coil — of the next. A switch that controls a switch that controls a switch. And once devices can control each other, you can arrange them to make decisions: only light this lamp if both of these switches are on; or if either one is; or if this one is not.
If those words — AND, OR, NOT — sound suspiciously like logic, that’s the punchline of this whole series. In 1937, a young engineer named Claude Shannon proved, in what’s often called the most important master’s thesis ever written, that networks of these humble relays could carry out the full machinery of Boolean algebra — the mathematics of true and false. Wire relays the right way and they don’t just switch; they reason. We’ll build exactly that, gate by gate, starting in the next post.
For now, sit with the wonder of it: every photo on your phone, every word in this article, every video game and spreadsheet and conversation, is — at the bottom — a descendant of this one click. Strip a computer down far enough and you arrive here, at a switch thrown by electricity.
That’s also why this is such a good place to start learning. You don’t need a circuits degree or a soldering iron to understand a relay — you just watched one work. From this single, visible, audible idea, everything in computing is built up one understandable step at a time. It’s the perfect first rung for a curious kid, a student peeking under the hood, or an engineer who wants to feel the foundations again.
What you just learned — and where we go next
In one post you’ve gone from “a relay is some electrical part” to understanding, from first principles:
- A relay is a switch that electricity controls — a coil pulls an armature that moves a contact.
- Wired normally open it’s a buffer; wired normally closed it’s an inverter (a NOT).
- Because one relay can control another, relays can be chained — and chained switches can compute.
Next in Building a Computer from Relays, we’ll put two switches together and meet the first real logic hiding in plain sight: switches in series behave like AND, switches in parallel behave like OR. You’ll toggle both and feel the rules of logic appear before anyone even names them — setting the stage for Shannon’s big idea.
Want to skip ahead and just play? Every circuit in this series lives in the DigiSim Relay Lab — drag relays onto a canvas, wire them up, and hear a computer think. Start free; the click is waiting.