A line reports 10 percent defective from 500 inspected garments, while another reports 6 percent from 50. The second result looks better, but its much smaller sample leaves more uncertainty to consider before ranking the lines.

A defect rate confidence interval helps answer that question by showing the sampling uncertainty around the estimated proportion of defective units. This guide explains the full calculation, includes a short Python routine and works through a zero-defect result. The method is useful only when the counts and the sampling plan fit the question being asked.

All factory examples below are illustrative. They are not industry benchmarks or acceptance limits.

Define the unit and the defect rule

Give each sampled unit one outcome: defective or not defective under the agreed rule. Count a garment once in the defective-unit total even if it has several faults, while keeping the separate fault records for diagnosis.

Suppose an inspector checks 100 garments. Eight garments have one fault each, and two have three faults each. There are ten defective garments and fourteen recorded faults. The defective-unit rate is 10 ÷ 100 = 10 percent. The fault count gives 14 defects per hundred units, or DHU. Those figures describe different things.

The DHU guide develops that distinction for garment reports. NIST's guidance on count data also separates nonconforming items from individual nonconformities. The Wilson calculation here needs a count of units with the stated binary outcome.

Define which findings make a unit defective for this report. A loose thread, a failed seam and a safety concern may have different rules and actions. The rate should not change merely because two inspectors applied different definitions.

State what the sample represents

Write the population or process of interest before calculating an interval. It might be one finished lot, one line's first-pass output during a shift, or a defined group of orders. The inspection stage matters because first-pass results and results after repair answer different questions.

Record the dates, style, line, lot and selection method. A sample from the first bundle cannot automatically describe the whole shift, just as a targeted sample cannot automatically describe all pieces.

Also decide how repeat inspections are handled. A garment checked three times after repair is still one garment. Counting all three checks as independent units can make the sample look larger than it is and change the meaning of the rate.

Keep the inspection event and the garment identity where the process allows it. A small amount of traceability at collection makes later disputes much easier to resolve. It also lets the team separate first-pass quality from repair success.

Understand what a confidence interval adds

The observed proportion is a point estimate calculated from the defective-unit count, while the interval adds a range based on a statistical method and its assumptions. NIST presents the Wilson bounds for a binomial proportion.

A two-sided 95 percent confidence method concerns repeated sampling. If the same method were used on many suitable samples, its intervals would cover the fixed underlying proportion at about the stated rate. The method does not say that 95 percent of garments conform. Nor does the interval predict the defect rate of the next batch.

Wilson coverage is approximate and is not exactly 95 percent for every possible true proportion and sample size. Hofer and Held's comparison studies several binomial interval methods and how their performance differs. There is no need to claim that one method is perfect to use it clearly and consistently.

The Wilson interval avoids some problems of the simple normal, or Wald, interval. In particular, it stays within the possible proportion range and does not collapse to zero width when no defective units are observed. It cannot fix a biased sample or an incorrect inspection record.

Keep fractions and percentages separate

Let x be the number of defective units and n the number inspected, with both inputs recorded as integer counts. Require n to be positive and x to lie between zero and n. Let p = x ÷ n be the observed proportion.

Use p as a fraction in the formula. Six percent is 0.06, not 6. Convert the final bounds to percentages by multiplying by 100. This simple unit check catches many spreadsheet errors.

For a two-sided 95 percent interval, the calculations here use z = 1.96. This is a rounded standard-normal value. Use the same value throughout the example so intermediate results agree.

A one-sided bound serves a different purpose and uses a different critical value, so select the appropriate method before reviewing the result. Set the confidence level and method before reviewing the outcome.

Calculate the Wilson interval in three parts

The formula can be split into a denominator, an adjusted centre and a half width. That makes a worksheet easier to check than one long expression.

Denominator d = 1 + z² ÷ n.

Adjusted centre c = [p + z² ÷ (2 × n)] ÷ d.

Half width h = z × √[p × (1 − p) ÷ n + z² ÷ (4 × n²)] ÷ d.

Lower bound = c − h.

Upper bound = c + h.

The adjusted centre belongs to the interval calculation and does not replace the observed proportion p in the quality report. Show the count-based rate and the interval together.

Keep enough precision during the calculation. Round the final reported percentages, not each intermediate step. A calculator showing a small negative value close to zero at a boundary may reflect floating-point rounding, but a materially negative result signals a problem that needs checking.

Work through twelve defective garments out of two hundred

Assume a suitable random sample has 12 defective garments among 200 inspected. The observed proportion is 12 ÷ 200 = 0.06. Using z = 1.96 gives z² = 3.8416.

The denominator is 1 + 3.8416 ÷ 200 = 1.019208. The adjusted centre is [0.06 + 3.8416 ÷ 400] ÷ 1.019208, which is about 0.06829224.

For the half width, first calculate the quantity inside the square root. Then take its square root, multiply by 1.96 and divide by 1.019208. The half width is about 0.03364039.

Calculation item

Value

Meaning

Defective units x

12

Each defective garment counted once

Inspected units n

200

Units in the stated sample

Observed proportion p

0.060000

A 6.00 percent observed rate

Adjusted centre c

0.06829224

An intermediate value

Half width h

0.03364039

An intermediate value

Lower bound

0.03465185

About 3.47 percent

Upper bound

0.10193264

About 10.19 percent

A clear report would state that 12 of 200 sampled units were defective, for an observed rate of 6.0 percent. The two-sided 95 percent Wilson interval is about 3.47 to 10.19 percent. Add the sampling scope and selection method to that statement.

The range is not symmetric around the observed 6 percent, which is expected with the Wilson score method. Do not alter a bound to make the display look balanced.

Use a short calculation routine

The following Python function uses the standard library. It accepts ordinary integer counts, rejects invalid inputs and returns the lower and upper bounds as fractions. It uses the same rounded z value as the worked example.

from math import sqrt

def wilson(x, n):
    if type(x) is not int or type(n) is not int:
        raise ValueError("Use integer counts")
    if n <= 0 or not 0 <= x <= n:
        raise ValueError("Require n > 0 and 0 <= x <= n")
    z = 1.96
    p = x / n
    d = 1 + z**2 / n
    c = (p + z**2 / (2 * n)) / d
    v = p * (1 - p) / n + z**2 / (4 * n**2)
    h = z * sqrt(v) / d
    return max(0.0, c - h), min(1.0, c + h)

lower, upper = wilson(12, 200)
print(round(100 * lower, 2), round(100 * upper, 2))

For the worked counts, the printed percentages are 3.47 and 10.19. The boundary clipping only protects against tiny floating-point errors. The formula itself is bounded between zero and one. The routine validates the arithmetic inputs but cannot assess whether the sampling design supports independent outcomes with a common probability.

Shirt inspection area

If a maintained statistics package is preferred, statsmodels documents the Wilson option. In proportion_confint, select method="wilson" and alpha=0.05 for a two-sided 95 percent calculation. The documented default method is normal, so do not omit the method choice. A package may use a more precise normal critical value than 1.96, causing tiny rounding differences.

Check a worksheet or program against known counts before adding it to a dashboard. Include zero defective, all defective and the 12-of-200 example. Reject a missing or zero denominator instead of silently displaying zero percent.

Compare line results with their sample sizes visible

Return to the opening example. Assume both samples use the same defective-unit rule and that the model assumptions fit. The counts and intervals are:

Sample

Defective units

Inspected units

Observed rate

Two-sided 95 percent Wilson interval

Line A

50

500

10.00 percent

7.67 to 12.94 percent

Line B

3

50

6.00 percent

2.06 to 16.22 percent

Zero-count example

0

100

0.00 percent

0.00 to 3.70 percent

Line B has the lower observed rate and a much wider interval. Calling B better from the percentage alone overlooks that uncertainty. It also overlooks possible differences in product mix, inspection coverage and the conditions of work.

Interval overlap is not a formal test of the difference between two proportions. If the decision needs that comparison, use a method designed for the difference and check its assumptions. Do not treat two separately calculated intervals as a complete comparison procedure.

First ask whether the comparison is fair. One line may make a complex style while another makes a repeat style. One sample may cover the whole shift while another covers only its strongest hour. More arithmetic will not make those scopes equivalent.

Read a zero-defect result with care

Zero defective units in 100 inspections means exactly that: none were found in the inspected sample under the stated rule. It does not prove the underlying defective-unit probability is zero.

For x = 0, the Wilson upper bound simplifies to z² ÷ (n + z²). With n = 100 and z² = 3.8416, the bound is about 0.036995, or 3.70 percent. The lower bound is zero.

A larger suitable sample with zero findings produces a smaller upper bound. For example, zero of 400 gives an upper bound of about 0.95 percent using this method. The difference shows why the sample count must travel with the reported zero.

Do not interpret either result as permission to ignore a critical finding, skip required checks or release a lot. The AQL inspection guide addresses a separate acceptance decision. Follow the agreed acceptance plan and defect rules; a confidence interval does not replace them.

Check independence and changes within the sample

A simple binomial model uses independent outcomes with a common probability of the stated event. Garments within one bundle may share fabric, machine settings or handling. If those shared conditions create strong dependence, treating every unit as independent can overstate the information in the sample.

Consider a sample of 100 pieces from one short run and a sample spread across the shifts of interest. Both have n = 100, but they may answer different questions. Because the formula sees only x and n, the sampling record must explain the difference in conditions.

Targeted inspection can be valuable for finding suspected defects quickly, but its selection process creates another limitation. Yet its rate describes the targeted set unless a suitable design supports wider inference. Do not relabel it as a random estimate for the whole lot.

If a large share of a finite lot is inspected without replacement, consider a method suited to that finite population. The standard independent-trial calculation may not fit the exact lot question. Keep a full inspection of a particular lot separate from a sample intended to estimate an ongoing process.

Keep estimation, monitoring and acceptance separate

An interval estimates a proportion under a model. A control chart studies a process through time. An acceptance plan determines an action for a lot under agreed rules. All three can use inspection counts, but they have different jobs.

The SPC guide explains the monitoring question. One pooled rate can hide a change halfway through the period. An interval around that pooled value does not prove the process was stable.

Preserve time order when investigating a change. A machine adjustment, new material lot or revised inspection rule may divide the data into different conditions. Report those conditions before claiming that a single average represents normal performance.

For improvement work, compare like periods and keep the original definitions. If the inspection rule changes at the same time as the process, explain both changes. A lower reported rate may reflect different detection rather than better production.

Combine counts only when the scope makes sense

If two samples belong to the same reporting scope, combine their counts before calculating the overall rate. Do not take a simple average of percentages when the sample sizes differ. The larger sample represents more inspected units.

For example, one sample contains 10 defective units out of 100. Another contains 10 out of 900. The combined observed rate is 20 ÷ 1,000 = 2 percent. The simple mean of 10 percent and about 1.11 percent is about 5.56 percent, which is not the combined unit rate.

Correct arithmetic does not settle whether pooling is wise. If the samples come from different styles or process conditions, retain those labels. The overall 2 percent may answer a total-inspected-output question while hiding a much worse result in the first group.

Nor does adding counts automatically justify a single binomial interval. Review the model and sampling design for the combined data. If the groups have different defect probabilities, a method that accounts for those differences may be needed.

A dashboard that shows both overall counts and relevant groups helps readers distinguish a change in quality from a change in the mix of work inspected. Keep the same grouping rules when comparing periods.

Decide what more data would resolve

A wide interval may call for more comparable observations, but collecting more is not always the first step. If unit identity is missing or the defect rule is disputed, resolve those issues first. A larger count of inconsistent records can give a falsely reassuring display.

Set the purpose of additional sampling. The team may need a narrower estimate, evidence about a suspected time period or a fair comparison of two processes. Those aims can require different designs. The convenient number of pieces available at a table should not set the whole plan.

Plan sample size with the decision and desired precision in mind. Do not repeatedly inspect until an interval happens to support a preferred claim. Such stopping can change the statistical properties of the method. If repeated review is part of the design, choose a method that accounts for it.

Publish a record that can be checked

Show x, n, the observed rate, interval bounds, confidence level and method. Add the dates, inspection stage, defect rule and sampling method. Name the person who can resolve disputed counts.

Display no estimate when n is zero or missing. Do not convert missing inspection data into a perfect zero-defect result. Keep invalid counts visible as a data issue for correction.

Start with one existing sampled-rate report. Add the Wilson interval, check the counts against the source log and review what population the sample can support. The result should help people ask a better quality question while leaving immediate defect correction and lot-release duties clear.

The intervals matter when defect data are compared, so see stratifying garment defect data before comparing lines, and use the same approach to interpret measurement ratios in textile energy performance indicators.

Wilson Score Formula and Zero-Defect Upper Bounds for AQL Samples

Standard normal-approximation ("Wald") confidence intervals break down on garment inspection data whenever observed defect rates are near 0% (for example, 0 or 1 defective piece in a sample of 80), often producing impossible negative lower limits or a false 0% upper bound. The Wilson score interval remains strictly bounded between 0% and 100% and accurate even at small defect counts:

Wilson Bounds = [ p̂ + z²/(2n) ± z × √( p̂(1 − p̂)/n + z²/(4n²) ) ] ÷ [ 1 + z²/n ]

where p̂ = k / n is the observed defective fraction, n is the inspected sample size, and z = 1.96 for a 95% confidence level. When k = 0 defects are found, the formula simplifies cleanly to an upper confidence bound of z² ÷ (n + z²):

ISO 2859-1 Sample Size (n)Observed Defective Garments (k)Observed Defect Rate (p̂)95% Wilson Lower Bound95% Wilson Upper Bound
50 (Code H)00.00%0.00%7.13%
80 (Code J)00.00%0.00%4.58%
125 (Code K)00.00%0.00%2.98%
200 (Code L)00.00%0.00%1.88%
315 (Code M)00.00%0.00%1.20%
500 (Code N)00.00%0.00%0.76%

Notice the operational takeaway: finding zero defects in a 50-piece inline audit does not prove the lot is below AQL 2.5—the true defective rate could still be as high as 7.13% at 95% confidence. Combine Wilson interval bounds with the AQL 2.5 sampling inspection chart and DHU & defect rate calculator when comparing quality across lines of different output volumes.

References