Most of these terms- error, defect, fault, failure and bugs are used interchangeably but there is difference between them. Some of these terms are very much different from others.
An error is a mistake made by human that leads to discrepancy between the actual and the expected result.
A defect is a problem in the functioning of a software system during testing. ISTQB defines a defect as "A flaw in a component or system that can cause the component or system to fail to perform its required function, e.g., an incorrect statement or data definition."
A fault is an incorrect step, process or data definition in a software product.
A bug is a flaw in a software system that causes the system to behave in an unintended manner.
A failure is inability of a software system to perform its operations within the specified performance benchmark. As per ISTQB, "a defect, if encountered during execution, may cause a failure of the component or system".
So, we can say that a mistake made by humans during coding is called error, an error found during the testing phase is called defect, a defect to be resolved by development team is called a bug and when a build does not meet its specifications then it is termed as failure.