What are defect leakage, DRE and defect density and how do you calculate them?
Defect leakage is the share of defects missed into production out of all found: production bugs ÷ (pre-release bugs + production bugs). DRE is the complementary share, caught before release, that is 100% minus leakage. Defect density is defects per unit of size (for example KLOC), used to compare modules. Leakage is final only after a fixed observation window, and the formula and which defects count are decided in advance.
QA Fundamentals · Quality metrics
A release had 45 bugs found and 5 more from production. Is that good, and how do you calculate it?
After a release five complaints reach support and turn out to be defects. The team asks: is this a normal result of testing or did we miss something? "Seems fine" is not an answer, because next quarter there is nothing to compare the five bugs with. Three metrics give a language for this conversation: defect leakage (how many we missed), DRE (how many we caught) and defect density (where defects concentrate). The lesson shows how to calculate them and why the same numbers can be read wrongly.
How it works and why. All three metrics rest on one thing: each defect has a known place where it was found (before release or in production) and a context size (release, module). So the first thing to set up in the tracker is a "found in production" mark (a label, a field or an environment type) and a link from a bug to a release or module. Without it the metrics must be counted by hand, which means rarely and with errors.
| Metric | Formula | The question it answers |
|---|---|---|
| Defect leakage | prod bugs ÷ (bugs before release + prod bugs) × 100% | What share of defects did we miss? |
| DRE (Defect Removal Efficiency) | bugs before release ÷ (bugs before release + prod bugs) × 100% | What share of defects did we catch? It is 100% minus leakage |
| Defect density | number of defects ÷ size (KLOC, function points, story points) | Where are there more defects than size alone explains? |
In ISTQB terms the closest indicator to DRE is the defect detection percentage (DDP): the share of defects found by a given test level out of all found at that level and later. That is the idea of a "phase": DRE can be calculated for each stage separately (code review, unit, integration, system tests, production) to see where defects slip through. Defect density exists to compare the incomparable: a module with twenty bugs can be healthier than a module with six if the first is five times larger.
One release: what we caught and what we did not
Example: the calculation and two ways to misread it. Data of one release with a 30-day window:
Release 2.15, post-release window: 30 days.
before release from prod total
all defects 45 5 50
Major and above 38 4 42
leakage (all) = 5 / 50 = 10% DRE (all) = 90%
leakage (Major+) = 4 / 42 ≈ 9.5% DRE (Major+) ≈ 90.5%
Defect density by module:
Payments 12 defects / 8 KLOC = 1.5 per KLOC
Profile 9 defects / 1.5 KLOC = 6.0 per KLOC
The first thing visible: counting only Major and above gives almost the same picture (9.5% against 10%), so minor bugs do not distort the conclusion. If there were far more minor ones, the "all defects" metric would show the activity of testers, not quality. That is why the criterion "which defects we count" is fixed in advance and not changed. Second: defect density showed what counts alone do not. "Payments" has more defects (12 against 9), but in Profile the density is four times higher (6.0 against 1.5 per KLOC), and that is where to look. Still, density is a reason to ask a question, not a verdict: Profile could be small and complex while Payments is big but simple.
Limits and alternatives. The leakage of a release is final only when the observation window has ended. Calculated after three days it looks great, because users have not yet had time to find the bugs. So the window (for example, 30 days) is fixed and releases are compared with equal windows. The second nuance: what counts as a "bug from production". A change request that came in as a bug shifts the numbers, so it is filtered out during the analysis. The third: leakage depends on how many defects were introduced. A team that catches everything but received very defective code in a release will have a low leakage and still many defects overall, so these metrics are read together with the number of open ones and with the trend. The fourth: defect density depends on the unit of size, and KLOC is not comparable across languages, so modules of one system are compared, not different projects. Alternatives or additions: escaped defects by severity, the lifetime of a defect in production, DRE by stage.
Common mistakes.
- Calculating DRE three days after a release: most production defects are not found yet, and the number is too good.
- Mixing bugs and change requests: leakage grows not because of testing but because of imprecise requirements.
- Not fixing which defects are counted: one quarter counts everything, the next only Major, and the trend is broken.
- Comparing the density of modules of different nature without context: a front-end form and a payment core have different complexity.
- Making leakage a personal target for QA: then production bugs start to be classified as "not ours", and the metric stops working.
Check yourself
A team found 18 defects before a release and 2 in production within a month. A week after the release a developer boasts: "Our leakage is 0%". What is wrong with this statement?
Answer
The observation window has not ended: users are only starting to find defects, so 0% is incomplete data. Only after a fixed window (say, 30 days) can leakage be compared with other releases. For this release, with two production bugs, the final value is 2/20 = 10%, not 0%.
The defect density of module A is 1.2 per KLOC, of module B 5. Does this mean B is tested worse?
Answer
Not necessarily. A high density can mean more defects, better detection, more complex logic or frequent changes. It is a reason to dig: check whether the defects were found by testing or by users, how the module changes, whether its requirements are unclear. A conclusion about the quality of testing is made by the DRE of this module, not by density alone.