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. 
AI that finds every edge case for you image
Transform your inputs into a ready-to-run test suite. Test both web UIs and backend APIs in minutes with KushoAI.
Explore MoT
TestBash Brighton 2025 image
Wed, 1 Oct
On the 1st & 2nd of October, 2025 we'll be back to Brighton for another TestBash: the largest software testing conference in the UK
MoT Foundation Certificate in Test Automation
Unlock the essential skills to transition into Test Automation through interactive, community-driven learning, backed by industry expertise
This Week in Testing
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.