Afternoon of September 9, 1947 — 15:45. The Harvard Mark II — 25 tons, 13,000 relays — has been quietly returning wrong answers. The operator team is tracing the fault; they open Panel F and reach Relay #70. There, between the electrical contacts, they find something no repair manual ever mentioned: a real moth.
They pull the moth out, tape it into the logbook, and write next to it: "First actual case of bug being found." But the story has a twist few people know: the word "bug" was not born that night. In fact, the sentence in the logbook is only funny once you know where the word actually came from...
#
Is the Story Actually Real? Yes — and the Moth Still Exists
This is one of those stories that feels too good to be true — except it is true. The 1947 moth incident really happened, and the logbook page with the moth still taped to it is held today at the Smithsonian's National Museum of American History. The sentence written beside it reads, verbatim:
“First actual case of bug being found.”
handwritten in the Mark II logbook — September 9, 1947
But two popular beliefs about the story are simply wrong. First, the word "bug" was not coined that night — it had been engineering slang for decades before computers existed. Second, what they found was not a software bug at all; it was a completely physical hardware fault, with a completely down-to-earth cause: an insect wedged inside an electric switch.
The true part
a moth was stuck in Relay #70, Panel F; the logbook is real and now sits in a museum
The mythical part
"the word bug was invented in 1947" and "it was the first software error in history"
So let's start from the beginning: what kind of machine was the Mark II? Why did it have relays at all? And how could a soft, winged, brainless creature take a multi-ton computer out of service?
#
A 25-Ton Machine Made of 13,000 Electric Switches
The Harvard Mark II — also called the Aiken Relay Calculator — was completed in 1947 at Harvard's Computation Laboratory under Howard Aiken, funded by the U.S. Navy. Its heart was the relay: an electromechanical switch that flips itself using electricity. It works in four simple steps:
1
The coil is energized — and acts as a magnet
2
The metal armature is pulled in — with that famous "click"
3
The contact closes — the second circuit is connected
4
Power off, armature released — the circuit opens; ready for the next command
Here is the key point: a relay has only two states — closed or open. So each relay is exactly one bit: zero or one. The Mark II had about 13,000 relays that together formed the machine's memory and logic; it weighed 25 tons, covered more than 4,000 square feet of floor space, and ran at roughly eight additions per second. For comparison:
Feature
Mark II (1947)
A modern phone
Switching elements
~13,000 relays
~20 billion transistors on a chip
Speed
~8 additions per second
trillions of operations per second
Weight / footprint
~25 tons / 4,000+ sq ft
a few grams in your pocket
Operating sound
a constant rain of clicks
silence
That last row is not a joke: the Mark II ticked constantly while running — thousands of relays opening and closing several times a second each. Accounts say experienced operators could sometimes hear when something wasn't working right, from the rhythm of the clicks alone — like a mechanic who can tell where an engine problem is just by listening.
#
September 9, 1947, 15:45
Mid-computation, the machine starts delivering wrong answers. No error message, no blue screen, no stack trace — just numbers that were not right. The operator team knows the problem lives somewhere among those 13,000 relays, and begins a systematic hunt: section by section, panel by panel. Eventually they reach Panel F, Relay #70, and open its cover.
There, between the metal armature and the contact, a moth is wedged. A large one, which had probably flown toward light or warmth the night before and ended its life in the wrong place. The operators pull it out — and do the thing that makes it the most famous insect in computing history more than seventy years later: they tape it into the logbook and write the sentence reconstructed below:
mark2_logbook.txt
Harvard Computation Laboratory - Log Book, Mark II
1947-09-09 15:45
Relay #70, Panel F
Moth found stuck between the relay contacts.
Removed & taped into this logbook.
"First actual case of bug being found."
Notice the word actual. Why "actual"? Because to any engineer of that era, "bug" was a perfectly familiar word — an abstract thing, the maddening fault that every invention ships with. But this time, for the first time, the bug that was found was the word itself: a real insect, with wings and legs. The logbook sentence is essentially an engineering joke — exactly the kind you still find in commit messages and code comments today.
ⓘ
Where is the moth now? The logbook page, with the moth still taped to it, is part of the collection of the Smithsonian's National Museum of American History. Grace Hopper later entrusted the page to the museum and happily told the story for the rest of her life. You could call it the oldest bug-report attachment in history.
#
How Can One Moth Stall a 25-Ton Computer?
The mechanics of the failure are almost embarrassingly simple. We saw that the relay's armature must physically reach the contact to close the circuit. Now imagine a moth's body wedged in that few-millimeter gap: no matter how hard the electromagnet pulls, the armature never reaches the contact. The relay is commanded to close, but its circuit stays open.
Healthy relay
close command → armature snaps in → the correct bit (1) is read
Blocked relay
close command → moth's body in the way → the bit always reads wrong (0)
One permanently-wrong bit sounds harmless; but in a machine whose entire memory and logic are built from such bits, it means one binary digit of some number is silently misread, every single time. The result: with no warning whatsoever, the machine confidently returns wrong answers. Sound familiar? That is precisely the behavior we get from software bugs today — with one big difference: the 1947 bug could be seen with the naked eye, removed with tweezers, and taped into a logbook.
#
But the Word "Bug" Was Not Born That Night
The most popular misconception about this story is that "the word bug was invented at Harvard in 1947." It wasn't. By the time it reached computers, the word was already old. The most famous document is a letter from Thomas Edison to his collaborator Theodore Puskás, dated 1878 — sixty-nine years before the Harvard moth:
“…then difficulties arise — this thing gives out and [it is] then that
‘Bugs’ — as such little faults and difficulties are called —
show themselves…”
Edison, 1878 — already using "bugs" as the standard engineers' name for little faults
Edison and the engineers after him had been calling stubborn device faults "bugs" for decades, and things like the "bug trap" — a rig for flushing faults out — already existed in the engineering vocabulary of that era. So when the Harvard team found the moth, they did not coin a new word; they made an old engineering pun literally come true for the first time. That is exactly why they wrote "actual": until then, bugs had been abstract and invisible; that afternoon, for once, they held the bug itself in their hands.
The common story
the word "bug" was invented in 1947 along with the moth story
The reality
the word was decades-old engineering slang; Harvard recorded its first literal occurrence
The word debug — hunting down and removing bugs — also spread in those early computing years, and Grace Hopper, whom we are just getting to, did more than anyone to keep both stories alive.
#
Grace Hopper: The Woman Who Made the Moth Immortal
Without Grace Hopper, the moth would have remained a small incident on one afternoon in 1947. Hopper was a mathematician who joined the U.S. Navy in 1943 and was assigned to Howard Aiken's computing machine project at Harvard; she started on the Mark I and worked on the Mark II and Mark III teams as well. After the war she moved into commercial computing — and did work that some consider among the most consequential in the history of software:
1
The first compiler in history (A-0, 1952)
a program that wrote other programs — at a time when nobody believed a computer could "program itself"
2
From FLOW-MATIC to COBOL
her language inspired COBOL — which, hard as it is to believe, still runs part of the world's banking systems today
★
A 79-year-old Rear Admiral
she served until 1986, aged 79 — the oldest active-duty officer in the Navy at the time; the destroyer USS Hopper and the Presidential Medal of Freedom carry her name
Hopper is also remembered for a small prop: pieces of wire about 30 centimeters long that she handed out in meetings to show how far light travels in a nanosecond — "here's a nanosecond, and here's a microsecond; now you see why your program is slow." She always told the moth story with the same delight, and the logbook page eventually went to the Smithsonian. Her famous line summed up how she had lived: "It's easier to ask forgiveness than it is to get permission."
#
The Night Debugging Was Born
Perhaps the most important part of the story is not the moth itself, but the method used to find it. Out of 13,000 relays, how did anyone reach Relay #70? Certainly not by opening every little cover and praying. The operators did what any sane engineer does: they narrowed the suspect range, step by step.
1
Reproduce the error — on which input does the machine answer wrongly?
2
Split the range — is the first half healthy or faulty? Either answer removes half the relays
3
Repeat on the faulty half — halve the space every time
4
Find the root cause & record it — remove the moth, log the incident
This is the half-split method still taught to electronics technicians today — and in algorithmic form, it is exactly binary search. Its beauty lives in this number:
probes ≈ ⌈log₂ N⌉ → 13,000 relays ≈ only 14 probes
each probe halves the search space; the cost of the search grows logarithmically, not linearly
ⓘ
Where does this idea live today? In git bisect. You give Git one good commit and one bad commit, and it walks the history with binary search, testing the middle commits, until it finds the culprit — the exact 1947 half-split, applied to the commit graph. Breakpoints, logging, and commenting out suspect code are all children of the same method: reproduce the error, narrow the range, see the root.
#
Let's Replay That Night in Python
We will simulate a small panel of 8 relays. The program stores one byte in the panel — but a (random) moth is stuck in one of the relays, so that bit always reads wrong. First we look at the symptom — the difference between the stored value and the readback — and then, using the very same 1947 half-split, we hunt the moth down:
moth_finder.py
# moth_finder.py - the night of Sept 9, 1947, replayed
import random
NUM_RELAYS = 8
moth = random.randrange(NUM_RELAYS) # the moth lands somewhere
# what the program stored vs what the panel reads back:
stored = 0b10110101
readback = stored ^ (1 << moth) # one stuck relay = one wrong bit
print(f"stored : {stored:08b} ({stored})")
print(f"readback: {readback:08b} ({readback})")
print("a relay is lying - time to hunt\n")
def section_is_faulty(lo, hi):
return lo <= moth < hi # the half-split probe
probes = 0
lo, hi = 0, NUM_RELAYS
while hi - lo > 1:
mid = (lo + hi) // 2
probes += 1
faulty = section_is_faulty(lo, mid)
print(f"probe {probes}: test relays {lo}..{mid-1} -> "
+ ("FAULTY"if faulty else"ok"))
if faulty: hi = mid
else: lo = mid
print(f"\nmoth found in relay #{lo} after {probes} probes")
print(f"Mark II's 13000 relays would need only "
f"{13000 .bit_length()} probes")
One sample run (the moth lands somewhere different every time):
output.txt
stored : 10110101 (181)
readback: 10110001 (177)
a relay is lying - time to hunt
probe 1: test relays 0..3 -> FAULTY
probe 2: test relays 0..1 -> ok
probe 3: test relays 2..2 -> FAULTY
moth found in relay #2 after 3 probes
Mark II's 13000 relays would need only 14 probes
Two things about this output. First, stored and readback differ in exactly one bit — bit #2 — and that "one always-wrong bit" is precisely what made the Harvard machine a liar that night. Second, the final number: 13000.bit_length() is just ⌈log₂ 13000⌉; even that monstrous 13,000-relay machine was, for patient engineers, at most about 14 probes away from the moth.
#
The Lab: You Are the Mark II Operator
It is 15:45 and the Mark II is returning wrong answers again. One of the 8 relays below is misbehaving, and in one of them sits the moth. Use the probe button to halve the suspect range; once the range narrows to a single relay, click that relay to pull the moth out. The question is: how many probes do you need?
moth_lab.exe — interactive
Relays outlined in cyan form the current suspect range. Faded relays have been ruled out.
Why are 3 probes enough? Each probe halves the search space: 8 → 4 → 2 → 1. Three halvings turn eight relays into one. That is why log₂ N is so powerful: make the search space a thousand times bigger, and you only need ten more probes.
#
Why a 1947 Moth Still Matters
Much of the charm of this story lies in one simple difference from today: the bug of 1947 was physical and visible. You could find it with your eyes, remove it with tweezers, and tape it into the logbook. Today's bugs — a race condition, a dangling pointer, a wrong token in a language model's probability array — have no body. We do the same job with breakpoints and logs and automated tests, but there is no moth to pin up.
What has survived unchanged from 1947 is the method and the attitude: reproduce the error. Narrow the suspect range step by step. When you see the root cause, fix it and record it — exactly what that team did by taping the moth into the logbook. They could not stop the moth from flying in, but they made sure that ever since, no bug goes undocumented.
And one last thought for those long debugging nights: when the clock is past midnight and the error is still winning, remember that the first computer bug in history was a brainless creature that simply flew toward the light. Sometimes the problem is deep and systemic; and sometimes it's just a moth you haven't found yet.
takeaway.txt
Every bug gets found eventually —
only the first one had wings.
Published: 2026-10-02 · Last updated: 2026-10-02
author.dat
Ali Zamani
Full Stack Developer
Full stack developer specializing in web, AI, and game development.