A bug is a fault in a program or a flaw in program correctness. They are commonly caused by error during the programming phase, which must be corrected by the developer, or failures in the APIs and libraries the developer depends on.
The bug word comes from times when giant room-sized computers produced a lot of heat and physical bugs felt attracted to it. When an error was traced to a moth being trapped in a relay and caused a program malfunction, the term ‘bug’ was coined for computers, although the term generally was in use since the 1870s.