Quick Links

You've probably heard it before: There's a "bug" in the software, causing something to malfunction or misbehave. What exactly is a computer bug and where did the term come from? We'll explain.

A Bug Is an Unintentional Error in Computer Software

A "computer bug" or "software bug" is a term for an unintentional programming mistake or defect in computer software or hardware. Bugs arise from human error in hardware designs or somewhere in the chain of software tools used to create computer applications, firmware, or operating systems.

A software bug is born when a programmer either makes a mistake while writing the software or writes code that works but has unintentional consequences that were not foreseen by the programmer. Removing bugs from software is called "debugging."

In today's software-driven world, bugs are serious business. Almost 20 years ago, the National Institute of Standards and Technology estimated that software bugs cost the U.S. economy almost $60 billion annually (about 0.6% of the GDP in 2002)---a number that has likely increased since then. While accurately quantifying the negative effects of bugs is difficult, it's easy to imagine how malfunctioning software can affect productivity. It can even put lives at risk in the realm of transportation or endanger vital infrastructure like power plants.

Why Do We Call Them Bugs?

The term "bug" predates the invention of computers, and we don't actually know who originally coined the term "bug" to refer to an engineering defect. In written records, historians have traced it back to Thomas Edison in the 1870s at the earliest.

Thomas Edison with his Phonograph ca. 1878
Library of Congress

Edison used the term in his personal notes and correspondence to mean a difficult problem that needed solving or an engineering defect that needed fixing. He even joked about the term being related to insects, writing in an 1878 letter:

"You were partly correct, I did find a 'bug' in my apparatus, but it was not in the telephone proper. It was of the genus 'callbellum.' The insect appears to find conditions for its existence in all call apparatus of Telephones."

While some take Edison's examples to mean that he coined the term "bug," it's possible that it originated from someone else earlier and that he merely popularized the term among his engineering friends and associates. The Oxford English Dictionary cites an 1889 example related to Edison that describes a bug as a metaphor for an insect crawling into a piece of equipment and making it malfunction, suggesting that a real bug doing just that might have originally inspired the term, similar to the term "fly in the ointment."

Ada Lovelace in an 1843 daguerreotype.
Ada Lovelace in an 1843 daguerreotype.

Setting the word "bug" aside for a moment, the first known person in history to realize that software may malfunction due to errors in programming was Ada Lovelace. She wrote about the problem way back in 1843 in her commentary about Charles Babbage's Analytical Engine.

"To this it may be replied that an analysing process must equally have been performed in order to furnish the Analytical Engine with the necessary operative data; and that herein may also lie a possible source of error. Granted that the actual mechanism is unerring in its processes, the cards may give it wrong orders."

In this quote, Lovelace refers to the actual calculating mechanism being error-free in the way that it processes data, but stipulates that the data fed to it by humans (as programmed on cards at the time) could give the machine the wrong instructions and thus produce the wrong results.

What About Grace Hopper's Moth?

For decades, books, magazines, and websites have erroneously reported that the term "bug" was coined by legendary computer scientist Grace Hopper when a moth flew into the relays of the Harvard Mark II computer and caused it to malfunction. As the story goes, she then taped the moth into a logbook and wrote a historical note: "First actual case of bug being found."

The famous Mark IV moth taped into a 1947 log book.
Smithsonian

While a moth really did fly into the Mark II in 1947, it wasn't the inspiration for the terms "bug" or "debug," both of which predate the incident. Also, it's not entirely clear that the moth actually made the computer malfunction, just that it was an amusing find while they were fixing other defects. Hopper made the story famous by telling it in a widely cited November 1968 interview:

"When we were debugging Mark II, it was over in another building, and the windows had no screens on them and we were working on it at night, of course, and all the bugs in the world came in. And, one night she conked out, and we went to look for the bug and found an actual large moth, about four inches wing span, in one of the relays beaten to death, and we took it out and put it in the log book and pasted scotch tape over it, and as far as I know, that's still in the historical log book up at Harvard (we found an actual bug in the computer)."

Hopper found the story amusing because, after frequently hunting down bugs in the computer (as in hardware and software defects), her team had finally found an actual, literal insect inside the computer. Hence the inscription, "First actual case of bug being found."

(As an interesting aside, Hopper describes the Mark IV moth as "beaten to death," likely because of the damage from getting caught within the movement of the computer's electromechanical relays, which suggests the computer continued to function while the moth was in there.)

1940s computer relays from an IBM instruction manual.
IBM

Historians don't know whether it was Hopper's log book, or who actually wrote the entry, but today, the Harvard Mark II log book resides in the National Museum of American History at the Smithsonian in Washington, D.C.

While the Mark II moth (Let's call him "Mark.") wasn't the first computer bug, it nevertheless persists as a physical and cultural symbol of a very real and difficult problem all programmers struggle with, and it's something we'll all be dealing with for years to come. Now pass me the bug spray, will ya?