A defect or bug is flaw in any software system that can cause the software system to fail to perform what its actually supposed to perform. A defect gets introduced in software work product due to the mistake made by the person creating that software work product like software requirements, design documents (High Level Design/Detailed Design), Test Plan, Test Scripts, Software Code etc.
While testing when a tester executes the test cases, he might observe that the actual test results do not match from the expected results. The variation in the expected and actual results is known as incident which will require investigation.
Every incident that occurs during testing may not be a defect or bug. An incident is any situation in which the software system has a questionable behavior, however we call the incident a defect or bug only if the Root Cause is the problem in the tested component and not other factors like test environment/test scripting issues.
Incidents can also occur by some other factors as well like testers mistake in test setup, environment error, invalid expected results etc.
We log these incidents just to keep track of the record of what is observed during the testing so that we can find out the solution to correct it.
A defect can be introduced in any phase of SLDC(Software Development Life Cycle) so it is very important that test team is involved from beginning of SDLC for detecting and removal of defects. The earliest the defect is detected and rectified, the minimal cost of quality will incur.
For Example: If the defect is identified in requirements phase then the cost of fixing it is just modifying the requirement whereas if the wrong requirement is designed and implemented in the code and found during the test execution phase then the cost to fix that defect will be very high as the fix needs to be done in requirement and then those changes need to propagate to design, development and testing again.