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.

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:

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.”

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.

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.”

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:

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.)

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?