A bug in software is the unintended misbehavior of a computer program. The word can likewise be used to described unwanted behavior in hardware, including computer chips or any hardware based on digital logic, and in analog hardware designs. Designation of problems as being caused by "bugs" is a tongue-in-cheek way for programmers and designers to avoid admitting directly that a mistake has been made.
Although the term "debugging" already existed in 1947, finding an insect that had caused a problem in a computer was an amusing occurrence and was recorded for posterity in an engineering notebook for the Mark II Aiken Relay Calculator at Harvard University. The operators affixed the moth to the computer log, with the entry: "First actual case of bug being found". In 1988, the log, with the moth still taped by the entry, was in the Naval Surface Warfare Center Computer Museum at Dahlgren, Virginia, which erroneously dated it 9 September 1945. The Smithsonian Institute's National Museum of American History and other sources have the correct date of 9 September 1947 (Object ID: 1994.0191.01)[1].
Another tongue-in-cheek way that "bug" gets used in engineering circles is when people say "It's a feature, not a bug", meaning that a program or device has a problematic behavior which no one will ever bother to fix.