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. 
Explore MoT
AI-driven testing in practice: from requirements to reliable automation image
See where AI genuinely helps, where it doesn’t, and how testers can stay firmly in control
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.
Into The Motaverse image
Into the MoTaverse is a podcast by Ministry of Testing, hosted by Rosie Sherry, exploring the people, insights, and systems shaping quality in modern software teams.
Subscribe to our newsletter