Confidence Interval for a Proportion Calculator

Offline — showing the version cached on .

Show all explainers, focus on one, or collapse them. You can also open or close each section directly.

Results

Observed proportion is 0.20000. Lower confidence limit is 0.07135. Upper confidence limit is 0.40103. Margin of error is 0.16484.

Observed proportion
Lower confidence limit
Upper confidence limit
Margin of error
Find
Did this solve your problem?

How to use this calculator

  1. Enter Number of observed events
    Enter the number of observed events as events_observed. This is the event count found in the sample. 1
  2. Enter Sample size
    Enter the total sample as sample_size. It supplies the N denominator used for the observed proportion. 1
  3. Enter Confidence level
    Enter confidence_level as a percentage. The source expresses interval confidence as 100(1-alpha) %. 1
  4. Read Margin of error

What this calculates

Use this calculator to estimate an observed proportion and its lower and upper confidence limits. Enter observed events, sample size, and confidence level. It reports the proportion, interval limits, and margin of error. 1

An exact method based on the binomial distribution supports the interval. The source describes limits for a proportion p using p_L and p_U. The calculation moves from short formulas to named stages and complete definitions. 1

Understand the interval

An interval has a lower confidence limit and an upper confidence limit. The source denotes them p_L and p_U. It describes (p_L, p_U) as an exact 100(1-alpha) % confidence interval for p. 1

The source uses p for the proportion under study. It uses p-hat for the observed proportion. The calculator exposes that quantity as observed_proportion. 1

Supply the observations

Calculation starts with observed data. The source describes sampled units and defective events as a setting for a proportion. A selected confidence level sets the stated confidence percentage. 1

Read the computed fields

The returned panel separates the observed quantity, interval endpoints, and margin. Its output names are observed_proportion, lower_bound, upper_bound, and margin_of_error. These are computed results rather than fields you enter. 1

The lower and upper values are the interval endpoints. margin_of_error describes the distance between those endpoints through the displayed calculation. Each output comes from the entered values and the page formulas. 1

Follow the calculation path

Calculate the observed proportion as N_d/N. Find the upper limit p_U by solving the binomial equation. Its sum from k = 0 through N_d equals α/2. Then find the lower limit p_L by solving the other equation. Its sum from k = 0 through N_d − 1 equals 1 − α/2. 1

Why the limits use separate equations

The source obtains p_U by solving a binomial equation. It obtains p_L through a related equation with a different summation endpoint and target. The displayed calculation keeps these limits as separate outputs. 1

Worked examples

Worked example — four observed events in twenty sampled units at ninety percent confidence: Observed proportion 0.20000

See inputs and calculation

Starting values

Number of observed events
4
Sample size
20
Confidence level
90 %
    1. Observed proportion: 0.20000
      Show arithmetic
      4 / 20
    2. Lower confidence limit: 0.07135
      Show arithmetic
      4 * f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1)) / (4 * f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1)) + 20 - 4 + 1)
      Full branch logic4 == 0 ? 0 : 4 * (4 == 0 ? 0 : f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1))) / (4 * (4 == 0 ? 0 : f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1))) + 20 - 4 + 1)
    3. Upper confidence limit: 0.40103
      Show arithmetic
      (4 + 1) * f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4)) / (20 - 4 + (4 + 1) * f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4)))
      Full branch logic4 == 20 ? 1 : (4 + 1) * (4 == 20 ? 0 : f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4))) / (20 - 4 + (4 + 1) * (4 == 20 ? 0 : f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4))))
    4. Margin of error: 0.16484
      Show arithmetic
      ((4 + 1) * f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4)) / (20 - 4 + (4 + 1) * f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4))) - 4 * f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1)) / (4 * f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1)) + 20 - 4 + 1)) / 2
      Full branch logic((4 == 20 ? 1 : (4 + 1) * (4 == 20 ? 0 : f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4))) / (20 - 4 + (4 + 1) * (4 == 20 ? 0 : f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4))))) - (4 == 0 ? 0 : 4 * (4 == 0 ? 0 : f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1))) / (4 * (4 == 0 ? 0 : f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1))) + 20 - 4 + 1))) / 2
    Original example and source context

    For the source example, sample 20 units and find 4 defective, giving an estimated proportion defective of 0.20. It reports p_L = 0.071354 and p_U = 0.401029, so the 90% confidence interval is (0.071, 0.400). 1

    Project and navigation context

    Resources, Stars, Watchers, Forks, Releases, Packages, Contributors, and Languages label the project. They are not calculator inputs or results. Footer and Footer navigation belong to page navigation. They do not compute intervals. 1

    The supplied authority material gives formulas, interval equations, validation wording, and computed examples. It gives no factual project details for these navigation labels. 1

    Key facts

    • The lower-bound formula has an explicit branch for events_observed == 0. 1 1
    • The upper-bound formula has an explicit branch for events_observed == sample_size. 1 1
    • margin_of_error is calculated from the difference between the returned bounds. 1 1
    • The source's exact method is based on the binomial distribution. 1 1

    How this is calculated

    Use the exact two-sided binomial method to estimate the observed proportion from the number of observed events and sample size, then report the lower and upper confidence limits at the chosen confidence level. The margin of error is half the interval width.

    Observed proportion

    p_hat
    • p_hat = Observed proportion
    Understand each part

    These names are shorthand for the exact calculations below, not different formulas.

    1. Observed proportion (p_hat)

      The observed event count divided by the sample size.

      See the definition of p_hatevents_observed / sample_size
    2. Significance level (alpha)

      The portion outside the selected two-sided confidence level.

      See the definition of alpha1 - confidence_level / 100
    3. Lower confidence limit (p_L)

      The lower confidence limit of the exact interval.

      See the definition of p_Llower_bound
    4. Upper confidence limit (p_U)

      The upper confidence limit of the exact interval.

      See the definition of p_Uupper_bound
    5. Margin of error (margin)

      Half the distance between the exact lower and upper confidence limits.

      See the definition of margin(p_U - p_L) / 2
    Follow the calculation with your values
    1. Observed proportion: 0.20000
      Show arithmetic
      4 / 20
    2. Lower confidence limit: 0.07135
      Show arithmetic
      4 * f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1)) / (4 * f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1)) + 20 - 4 + 1)
      Full branch logic4 == 0 ? 0 : 4 * (4 == 0 ? 0 : f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1))) / (4 * (4 == 0 ? 0 : f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1))) + 20 - 4 + 1)
    3. Upper confidence limit: 0.40103
      Show arithmetic
      (4 + 1) * f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4)) / (20 - 4 + (4 + 1) * f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4)))
      Full branch logic4 == 20 ? 1 : (4 + 1) * (4 == 20 ? 0 : f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4))) / (20 - 4 + (4 + 1) * (4 == 20 ? 0 : f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4))))
    4. Margin of error: 0.16484
      Show arithmetic
      ((4 + 1) * f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4)) / (20 - 4 + (4 + 1) * f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4))) - 4 * f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1)) / (4 * f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1)) + 20 - 4 + 1)) / 2
      Full branch logic((4 == 20 ? 1 : (4 + 1) * (4 == 20 ? 0 : f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4))) / (20 - 4 + (4 + 1) * (4 == 20 ? 0 : f_ppf(1 - (1 - 90 / 100) / 2, 2 * (4 + 1), 2 * (20 - 4))))) - (4 == 0 ? 0 : 4 * (4 == 0 ? 0 : f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1))) / (4 * (4 == 0 ? 0 : f_ppf((1 - 90 / 100) / 2, 2 * 4, 2 * (20 - 4 + 1))) + 20 - 4 + 1))) / 2
    Full formulas, symbols and sources

    observed_proportion = events_observed / sample_size

    Lower confidence limit

    lower_bound = events_observed == 0 ? 0 : events_observed * (events_observed == 0 ? 0 : f_ppf((1 - confidence_level / 100) / 2, 2 * events_observed, 2 * (sample_size - events_observed + 1))) / (events_observed * (events_observed == 0 ? 0 : f_ppf((1 - confidence_level / 100) / 2, 2 * events_observed, 2 * (sample_size - events_observed + 1))) + sample_size - events_observed + 1)

    Upper confidence limit

    upper_bound = events_observed == sample_size ? 1 : (events_observed + 1) * (events_observed == sample_size ? 0 : f_ppf(1 - (1 - confidence_level / 100) / 2, 2 * (events_observed + 1), 2 * (sample_size - events_observed))) / (sample_size - events_observed + (events_observed + 1) * (events_observed == sample_size ? 0 : f_ppf(1 - (1 - confidence_level / 100) / 2, 2 * (events_observed + 1), 2 * (sample_size - events_observed))))

    Margin of error

    margin_of_error = (upper_bound - lower_bound) / 2

    events_observed
    Number of observed events ()
    sample_size
    Sample size ()
    confidence_level
    Confidence level (%)
    observed_proportion
    Observed proportion
    lower_bound
    Lower confidence limit
    upper_bound
    Upper confidence limit
    margin_of_error
    Margin of error
    f_ppf
    the F value with these degrees of freedom having this probability at or below it

      Frequently asked questions

      Why might the interval not be symmetric?
      The source says the interval is not symmetric about the observed proportion. The lower and upper limits come from separate equations. Therefore, their distances can differ. Do not infer a symmetric interval from observed_proportion. 1
      What happens when no events are observed?
      When events_observed == 0, lower_bound returns 0. The upper bound still follows its displayed upper-bound calculation. margin_of_error then uses the returned endpoints. 1
      What happens when every sampled unit is an event?
      When events_observed == sample_size, upper_bound returns 1. The lower bound follows its own displayed calculation. margin_of_error then uses the returned endpoints. 1
      What does f_ppf mean here?
      The page formula uses f_ppf at the displayed arguments. The supplied material does not provide a prose definition for that name. Keep f_ppf as displayed rather than introducing a new page-specific shorthand. 1
      What does the source mean by F?
      The source says, “F is the cumulative density function for the binominal distribution.” This description belongs to the source's explanation of the binomial method. 1
      How does the confidence percentage connect with alpha?
      The source expresses confidence as 100(1-alpha) %. The page accepts confidence_level as a percent and places it inside divisions by 100. This connects the entered percentage with the displayed formula. 1
      When is the margin of error calculated?
      The margin_of_error calculation uses upper_bound and lower_bound. Those endpoint results must therefore exist before the margin is computed. The page then divides their difference by 2. 1

      Limitations & common mistakes

      • The page's choice limits events_observed to 0 through 1000; these edges are page limits, not formula limits.
      • The page's choice limits sample_size to 1 through 10000; these edges are page limits, not formula limits.
      • The page's choice limits confidence_level to 1 through 99.999 %; these edges are page limits, not formula limits.
      • Outside these page choices, the calculator refuses to answer.
      • Use an exact method based on the binomial distribution to obtain the confidence interval for the proportion.
      • The results are computed from the numbers you enter and are only as exact as those numbers; they are not a substitute for a measurement or a professional's judgement where one is required.

      Formula, sources, and review

      This calculation follows the formula published on this page and rests on 1 cited sources, listed under Sources below. Last checked .

      How we review

      Sources & methodology

      ConstantValueUnitSource
      confidence_interval_for_proportion_c121

      Sources

      • 1 Confidence intervals — Does the proportion of defectives meet requirements? — last verified