Grace Murray Hopper was a Navy officer who was instrumental in the development of COBOL, one of the first programming languages to use the English language to write code instead of assembly or machine language.
In 1947, computers used relays instead of transistors as they are today (or vacuum tubes some time between). Relays are little (usually magnetic) switches which are essentially a mechanical representation of binary (on or off).
When relays encountered foreign objects, they would no longer switch optimally, if at all. In 1947, a moth got caught on a relay and died. The team recorded the incident:
Relay #70 Panel F
(moth) in relay.
First actual case of bug being found.
They announced that they had “debugged” the system.
From that moment on, anything preventing a program from performing optimally or failing altogether has been referred to as a “bug”. On the other hand, “debugging” has strayed somewhat to not only mean removing bugs from a program but is also used to mean a programmer is stepping through code to ensure it works as planned (whether or not bugs exist).
The history of computers is very interesting. Sometimes slang terms like “bug” are easily adopted by the community. Sometimes terms like “core” are used to refer to things which have evolved away from the original implementation.
For more information about Grace Hopper and “bugs”, check out these resources: