Bug (engineering). In engineering, a bug is a design defect in an engineered system that causes an undesired result.

Although used exclusively to describe a technical issue, bug is a non-technical term; applicable without technical understanding of the system.

The term bug applies exclusively to a system that is (human) designed; not to a natural system; and that the issue is within the influence of human control. For example, humans have faults but not bugs, and a server crash due to natural disaster is not a bug.

In addition to or instead of defect, some use: error, flaw or fault.

Engineered systems is a broad classification encompassing but not limited to: software, computer hardware, electronics, circuitry and machinery.

The undesirable result can be classified and described many ways including: intermittent, transient, glitch, crash or hang.

Since desirability is subjective, what is considered undesirable to one may be considered desirable to another; even a useful feature.

History 
The Middle English word bugge is the basis for the terms bugbear and bugaboo as terms used for a monster.

The term bug to describe a defect has been engineering jargon since at least as far back as the 1870s  long before electronic computers and computer software. For instance, Thomas Edison wrote the following words in a letter to an associate in 1878:

In a comic strip printed in a 1924 telephone industry journal, a naive character hears that a man has a job as a "bug hunter" and gives a gift of a backscratcher.  The man replies "don't you know that a 'bug hunter' is just a nickname for a repairman?"

Baffle Ball, the first mechanical pinball game, was advertised as being "free of bugs" in 1931.

Problems with military gear during World War II were referred to as bugs (or glitches). 

In the 1940 film, Flight Command, a defect in a piece of direction-finding gear is called a bug. 

In a book published in 1942, Louise Dickinson Rich, speaking of a powered ice cutting machine, said, "Ice sawing was suspended until the creator could be brought in to take the bugs out of his darling."

Isaac Asimov used the term bug to relate to issues with a robot in his short story "Catch That Rabbit", published in 1944.

Computer pioneer and rear admiral, Grace Hopper, popularized a story about a moth that caused a problem in an early electromechanical computer. While Hopper was working on the Mark II and Mark III as Harvard faculty in about 1947, operators traced an error in the Mark II to a moth trapped in a relay. The moth was removed from the mechanism and taped in a log book with the note "First actual case of bug being found."

Reportedly, the operators, including William "Bill" Burke, later of the Naval Weapons Laboratory, Dahlgren, Virginia,  were familiar with the engineering term and probably making a joke by conflating the two meanings of bug (biological and defect).
Although probably a joke, the story indicates that the term was commonly used in the computer field at that time. 

The log book, complete with moth, is part of the collection of the Smithsonian National Museum of American History.

The related term debug also appears to predate its usage in computing: the Oxford English Dictionarys etymology of the word contains an attestation from 1945, in the context of aircraft engines.

"It's not a bug, it's a feature"
Since bug implies undesirable behavior, calling a behavior a bug is subjective. Behavior which is considered a bug by some may be considered a useful feature by others, hence a common phrase is "It's not a bug, it's a feature" (INABIAF). This quip is recorded in The Jargon File dating to 1975 but dates to 1971 when PDP-8 programmer Sandra Lee Harris at Digital Equipment Corporation (DEC) made the distinction between issues to be fixed in the code for DEC's FOCAL interpreter and those to be documented or clarified in the user manual.

Such behavior might be explicitly communicated to users, or might remain an undocumented feature.

References

Engineering concepts
Engineering