Understanding Defect Density: Complete Guide 2021

The quality of any software is estimated by the number of defects reported during its lifetime. A software with a very small number of defects is considered to be a good quality software while the one with a large number of defects is regarded as bad quality software.

But, it is unfair to label a software’s quality based on just the defects count. It also matters ‘how big a software is in which such several such defects are detected?’. So Defect Density is the metric used to include both these parameters for estimating the quality of a software. It is a metric that maps the defects in the software with the volume of the lines written to build the software.

What is Defect Density?

Defect Density is the ratio of the number of defects and the size of the software. Here, it is necessary to understand that bugs are not considered under defects. Defects are the deficiencies in the software that are confirmed. The formula to calculate Defect Density is:

Defect Density = Number of Defects/Size of the software

The size of software can be measured in the unit of the number of code lines or the number of function points. Defect Density in terms of lines of code is defined as the number of defects reported per 1000 lines of code i.e. KLOC

Defect Density Graph
Image Source: IEEE Computer Society

For example, if there are 15,000 lines of code in software and 150 confirmed defects are reported during the complete lifetime or a fixed duration of software. Then, the Defect Density will be calculated as

Defect Density = 150/15000

                           = 10 defects per KLOC

Defect density in terms of modules has been assigned the unit of defects per module. For example, there are 10 modules in software and a total of 50 defects have been detected. Then, the Defect Density will be calculated as

Defect Density = 50/10 

                           = 10 defects per module

Data required to calculate Defect Density

1. First of all, it is necessary to find the total number of defects detected in the software during the complete software development lifecycle. A defect in the software is the variation between the actual result and expected result which is detected by the developer or tester during the lifecycle.

2. The second data required is to obtain the total number of lines in the code or the number of function points.

what is Defect Density
Image Source: Visual Studio Magazine

Significance of Defect Density

1. Defect density helps in predicting the number of defects that may exist in the future development of the software.

2. It also helps in analysing ‘how efficient the testing process is in detecting defects and the amount of testing necessary to undertake?’.

3. It also helps in preparing a database of standard defect densities.

4. Defect density is a measure to track the progress, productivity and quality of the software.

5. Its value can be a factor to decide ‘whether the software or module should be released or not and is it able to offer seamless user experience and satisfy their needs?’.

6. The components with high defect density can be discovered easily and measures can be taken to fix the defects and bring the value down. 

7. It provides a way to compare the quality of any two software. 

8. Even the modules within the software can also be compared with the metric.

Suppose there are two softwares ‘A’ and ‘B’. Software ‘A’ has recorded 35 defeats in 5000 lines of code, which calculates it’s defect density equal to 35/5000 = 7 defects per KLOC. In software ‘B’ there are 60 defects reported in 15000 lines of code, which leads to its defect density equal to 60/15000 = 4 defects per KLOC.  From the above results, it can be observed that even if there were more defects in software ‘B’ but in terms of defect density it is of better quality than software ‘A’ with a lesser number of defects.

That’s why the size of the software is a very important parameter while comparing the quality of the software.

significance of Defect Density
Image Source: ResearchGate

What leads to variation in Defect Density?

1. The Lines of code might not accurately represent these metrics, depending upon the complexity of the program.

2. It may also vary depending upon the kind of defects taken into account for the calculation.

3. Even the time duration for which the metric is calculated may vary the defect density of a software. This duration can be a month, a quarter, a year or sometimes it is calculated at the end of the software development lifecycle.

4. It also depends upon the ability of the tester responsible for considering all important factors to obtain a logical and valuable result.

5. It depends upon the usability of the software that ‘whether a user will encounter a defect or not?’ which leads to variation in the defect count and hence Defect Density.

What does the Defect Density imply?

1. It helps in identifying the modules in the software that can affect its quality adversely and requires correction.

2. It makes it easy to track that the development of the software is in the right direction. A higher defect density will inform that the recent development need was not up to the mark.

3. It will also expose the weaknesses in the team and process, and actions must be taken to improve them.

4. Even it helps in predicting the amount of testing that will be sufficient and defect corrections that may be required in future software developments.

5. The metric values for two different modules will help in comparing the quality of their development and testing.

6. It also explains that ‘is the software or a module satisfactorily tested and ready for deployment or need more testing?’.

software development cycle
Image Source: Datarob


So, I hope now you understand ‘what is defect density?’. The Defect Density can be a very valuable metric to evaluate the quality of the development, testing and hence, the final product. It tells that 

  • How efficiently has the software been developed?
  • How effectively the software has been tested?
  • What are the possible number of defects expected to encounter and corrective actions required to improve the testing or development process?
  • Whether the software is ready to go live or not?