What is Defect Density?
Defect density is a quality metric that measures the number of confirmed defects divided by the size of the component, commonly per thousand lines of code (KLOC) or per function point or module.
Free to start · 7-day trial on paid plans
In depth.
Defect density normalizes raw bug counts by size so you can compare components fairly: 20 defects in a 2,000-line module is very different from 20 in a 200-line one. The formula is simply confirmed defects divided by a size unit, often defects per KLOC. Teams use it to spot fragile modules that may need refactoring or extra testing, to compare quality across releases, and as one input to release-readiness decisions.
The metric has real limitations, and naming them is the interview signal. Lines of code is a crude size proxy and is easy to game. Defect density depends heavily on how hard the code was tested, low density can mean clean code or simply weak testing. It also says nothing about severity: a module with one data-loss bug is worse than one with ten cosmetic issues at the same density. So defect density is useful as a trend and a comparison signal, not as a target to optimize directly.
It pairs well with other measures like defect escape rate and severity-weighted counts to give a fuller quality picture.
Why interviewers ask about this.
For QA lead, manager, and architect interviews, metrics questions are common. Quoting the formula is table stakes; the real signal is naming the limitations, especially that low density can mean weak testing rather than good code.
Example scenario.
A team finds module A has 8 defects in 1,000 lines (8 per KLOC) and module B has 2 in 1,000 (2 per KLOC). Before flagging A as low quality, the lead checks coverage and finds B was barely tested, its low density is a blind spot, not a strength, which is exactly why defect density is read alongside coverage.
Interview tip.
Give the formula, then immediately list two limitations: LOC is a weak size proxy, and low density can reflect weak testing rather than good code. Mentioning that it ignores severity rounds out a strong answer.
Frequently asked questions.
What is the defect density formula?
Defect density equals the number of confirmed defects divided by a size unit, most commonly defects per thousand lines of code (KLOC), but also per function point or per module.
What are the limitations of defect density?
Lines of code is a crude, gameable size proxy; low density can reflect weak testing rather than clean code; and the metric ignores severity. It is best read as a trend alongside coverage and escape rate, not optimized directly.
Related Terms
Explore related glossary terms to deepen your understanding.
Related Resources
Dive deeper with these related interview prep pages.
Free QA career tools, no account needed
Instant and private, everything runs in your browser. Try them before you sign up.
QA Resume Checker
Instant 0-100 score on automation keywords, impact, and ATS formatting.
QA Cover Letter Generator
A tailored 3-paragraph QA cover letter from your resume and a job post.
QA Application Tracker
Drag-and-drop kanban to track every QA application from Applied to Offer.
QA Take-Home Test Generator
A realistic take-home assignment with a scenario, tasks, and a rubric.
QA LinkedIn Headline Generator
A recruiter-searchable headline, About section, and skills list.
QA STAR Story Builder
Structure a QA behavioral answer with the STAR method and instant checks.
QA Bug Report Generator
Build a clean, reproducible bug report for Markdown, Jira, or plain text.
Boundary Value Analysis Generator
Generate boundary value and equivalence partitioning test cases from a range.
QA Metrics Calculator
Calculate DRE, defect leakage, defect density, and pass rate with interpretation.
QA Test Plan Generator
Build a structured test plan (scope, approach, criteria, risks) in Markdown.
Ready to Ace Your QA Interview?
Practice explaining defect density and other key concepts with our AI interviewer.
Join 1,200+ QA engineers already practicing with AssertHired.
Start your free QA interview