how to calculate mass defect code example Example: how to calculate defect density Defect density is the total number of defects per lines of code.