It is impossible to create software without mistakes. Software is created by people, and people tend to make mistakes. In addition, users may not use the program as expected and unintentionally enter invalid data, while the program also may not behave the way it should.
A defect (bug) is an error in a program which causes an incorrect and/or unpredictable operation; a defect is also a mismatch of the actual and expected result. Due to defects that occurred during code writing, a program may not perform its intended functions, work differently than required by the specification, or perform actions that are not expected. Such cases are called program failures.
All programs have bugs and they remain there even after release. It happens because it is impossible to conduct exhaustive testing. The reason is the lack of time, resources, and a huge number of input values and test scenarios. Usually, a software release contains minor bugs, while serious and critical bugs are fixed.
Defects can be found at different stages of development and can be detected at different levels of testing. The quality of the system depends on whether the bugs found are fixed, while the cost of fixing the bugs depends on the stage of software development at which the bugs are found.