Defect density

Defect density image

What is defect density?

Defect density measures how many bugs exist within a specific amount of code. It helps you quantify software quality objectively, and you can use it to compare modules, track improvements over time, and identify problematic code areas. 

Defect density works by normalizing defect counts against code size, creating a consistent measurement across different components.

Do you have any examples of defect density?

Here's an example calculation that shows defect density for a typical software module:

  • Total lines of code: 10,000
  • Number of defects found: 15
  • Size measurement: thousand lines of code (KLOC) = 10,000 ÷ 1,000 = 10 KLOC

The formula for defect density is:

  • Defect Density = Number of defects ÷ Size in KLOC

So:

  • Defect Density = 15 ÷ 10 = 1.5 defects/KLOC

This means your module contains 1.5 bugs per thousand lines of code, which helps you compare its quality against industry standards or other modules.

Why is defect density important?

Defect density provides an objective quality measure. It lets you track improvements, compare components, and identify areas that need additional testing or refactoring. Lower defect density usually indicates better quality.

What challenges exist with defect density?

Defect density depends on accurate defect reporting and doesn't account for variations in complexity. A low score might indicate high quality… or insufficient testing. Different languages and projects also have different acceptable ranges. 
TestBash Brighton 2025 image
On the 1st & 2nd of October 2025 we're back in Brighton for TestBash: the largest software testing conference in the UK
Explore MoT
Castelo Branco Meetup image
Tue, 6 May
The Future of Testing in an Automated World: Embracing Continuous Learning and A
MoT Software Testing Essentials Certificate image
Boost your career in software testing with the MoT Software Testing Essentials Certificate. Learn essential skills, from basic testing techniques to advanced risk analysis, crafted by industry experts. Early access available now at a discounted rate!
Leading with Quality
A one-day educational experience to help business lead with expanding quality engineering and testing practices.
This Week in Testing image
Debrief the week in Testing via a community radio show hosted by Simon Tomes and members of the community
Subscribe to our newsletter
We'll keep you up to date on all the testing trends.