P-Hat Calculator

Find the sample proportion (p-hat) from the number of successes and the sample size, with its complement q-hat. Optionally add the standard error, margin of error and a Wald or Wilson confidence interval, with every step shown.

Enter how many observations met your condition (the successes, such as "yes" answers) and the total sample size. Successes are counted inside the sample size, so x can never be larger than n.

A whole number from 0 up to n.
A whole number of at least 1.

Enter x and n above and the result appears here automatically.

Reset calculator?

Are you sure you want to reset? Your entered values and the current result will be cleared.

What this p-hat calculator does

P-hat is the sample proportion: the fraction of a sample that has some characteristic. If 42 of 120 people surveyed answered yes, then p-hat is 42 ÷ 120 = 0.35, or 35%. The calculator takes the number of successes and the sample size and returns p-hat as a decimal and a percentage, together with the counts you entered and the complement q-hat.

Short answer: p-hat = x ÷ n, where x is the number of successes and n is the sample size. It describes your sample and serves as a point estimate of the population proportion p. The standard error and confidence interval are optional extras, and they are only as sound as the sampling behind the data.

The basic result needs only two numbers. If you also want to know how much p-hat might vary, switch on the confidence interval option. That adds the estimated standard error, the critical value, the margin of error and the interval limits, and it names the method used for each interval. The two parts are kept apart on purpose: the point estimate is simple arithmetic, while the interval rests on assumptions that the page spells out below.

What to enter

Enter the number of observations that met your condition as x, and the total number of observations as n. Successes are counted inside the sample, so 42 yes answers in a sample of 120 means x = 42 and n = 120, not n = 162. If you know the failures instead, subtract them from n to get x. If you only have a percentage and a sample size, multiply them: 35% of 120 is 42.

  • Both entries are counts. They must be whole numbers, so 12.5 or a percentage typed as 35% is rejected with an explanation. Thousands commas (1,250) are accepted.
  • The sample size must be at least 1. A proportion cannot be formed from an empty sample.
  • Successes must lie between 0 and n. Zero successes and an all-success sample are both valid. They give p-hat = 0 and p-hat = 1.
  • Large counts are fine. The calculator accepts counts up to 1,000,000,000,000 and does the division at full precision, rounding only what it displays.
Successes, x
The number of observations that meet the condition you are counting. "Success" is a label, not a judgement: a defective part or a "no" answer can be the success.
Sample size, n
The total number of observations in the sample, successes and failures together.
Sample proportion, p-hat
The observed share of successes, x / n. It describes the sample and estimates the population proportion.
Complement, q-hat
The observed share of failures, 1 − p-hat, which is the same as (n − x) / n.
Population proportion, p
The true share in the whole population. It is a fixed but usually unknown parameter, which p-hat estimates.
Standard error, SE
The estimated spread of p-hat from sample to sample, which measures sampling variability.
Confidence level and z*
The confidence level (such as 95%) sets the critical value z* from the standard normal distribution. A higher level gives a larger z* and a wider interval.

P-hat formula and worked example

The sample proportion is the number of successes divided by the sample size. Its complement, q-hat, is the share of failures, which you can get either as 1 − p-hat or as (n − x) ÷ n.

  • Sample proportion: p-hat = x ÷ n
  • Complement: q-hat = 1 − p-hat = (n − x) ÷ n
  • Percentage = p-hat × 100
  • Estimated standard error: SE = sqrt(p-hat × (1 − p-hat) ÷ n)
  • Margin of error = z* × SE, where z* is the two-sided standard normal critical value
  • Wald interval: p-hat ± margin of error
  • Wilson interval: (p-hat + z*²/2n ± z* × sqrt(p-hat × q-hat/n + z*²/4n²)) ÷ (1 + z*²/n)
  • Sampling distribution of p-hat: mean = p, standard deviation = sqrt(p × (1 − p) ÷ n)

For 42 successes in a sample of 120, substitute into p-hat = x ÷ n to get p-hat = 42 ÷ 120. The division gives 0.3500, and multiplying by 100 converts it to 35.00%. The failures are 120 − 42 = 78, so q-hat = 78 ÷ 120 = 0.6500, and the two add up to 1. Choose Fill with an example to load these numbers.

The calculator keeps full precision through every step and rounds only the values it shows, using the number of decimal places you select. Rounding p-hat to two places before using it in later steps would shift the standard error and the interval slightly, which is why the intermediate values are not rounded.

Reading the result

A p-hat of 0.35 says that 35% of this sample had the characteristic. It is an observation about the sample, and it is also the natural estimate of the population proportion. It is not the population proportion itself. Draw another random sample of 120 from the same population and p-hat will probably come out a little different, a pattern known as sampling variability.

Three quantities are often confused. The population proportion p is the true share, fixed and normally unknown. P-hat is the share in one sample, and it changes from sample to sample. A p-value is something else entirely: it comes from a hypothesis test and measures how surprising the data would be if a null hypothesis were true. Across repeated random samples, the mean of p-hat equals p and its standard deviation is sqrt(p × (1 − p) ÷ n), so p-hat tends to land close to p and gets closer as n grows.

All of this assumes the data are a random sample. A very large sample that was collected in a biased way, such as an online poll that only some people answer, produces a precise estimate of the wrong thing. A bigger n does not fix a biased sample, and no formula on this page can detect one.

Standard error, margin of error and confidence interval

The standard error measures how much p-hat is expected to vary from sample to sample. The true standard deviation of p-hat needs p, which is unknown, so the calculator substitutes p-hat: SE = sqrt(p-hat × q-hat ÷ n). For 42 of 120 that is sqrt(0.35 × 0.65 ÷ 120) = 0.0435.

The margin of error scales the standard error by a critical value z*. At 95% confidence, z* = 1.9600, so the margin of error is 1.9600 × 0.0435 = 0.0853. The Wald interval, the normal-approximation interval taught in most courses, is p-hat ± margin of error, which here runs from 0.2647 to 0.4353. At 99% confidence z* rises to 2.5758, the margin of error to 0.1122 and the interval to 0.2378 to 0.4622. Only the interval changes with the confidence level: p-hat stays at 0.35.

A confidence level describes the method, not one interval. If you repeated the sampling many times and built an interval each time, about 95% of those intervals would capture the true proportion, provided the conditions hold. It is not correct to say there is a 95% probability that this particular interval contains p.

Margin of error at 95% confidence for p-hat = 0.30. Each fourfold increase in n halves the margin of error.
Sample size (n)Successes (x)p-hatMargin of error
3090.30000.1640
120360.30000.0820
4801440.30000.0410
19205760.30000.0205

A larger sample narrows the interval because the standard error contains n in the denominator, and the margin of error changes with the square root of n. Doubling the sample does not halve the margin of error. Quadrupling it does.

When the normal approximation can be trusted

The Wald interval relies on the sampling distribution of p-hat being close to normal. A common check is the success-failure condition: at least 10 successes and at least 10 failures in the sample. For 42 of 120 the counts are 42 and 78, so the condition is met. For 4 of 100 there are only 4 successes, so it is not. Textbooks do not agree on the threshold. Some use 5 and others use 10 or 15, so the calculator reports both the 10 and the 5 checks next to the counts and does not treat either as a guarantee.

Meeting the condition is not the whole story. The observations should be independent, which in practice means a random sample, and when sampling without replacement the sample should be a small part of the population, often taken to be under 10%. Neither can be tested from x and n alone, so they are assumptions you carry.

When the counts are small or p-hat is near 0 or 1, the Wald interval can behave badly. It can even run past the possible range: for 1 success in 20, the 95% Wald interval is −0.0455 to 0.1455, and a proportion cannot be negative. The calculator shows such limits as calculated and flags them, because trimming them to 0 would hide the fact that the approximation has failed. Zero successes or all successes give a Wald interval of zero width, which is not a believable statement about the population.

The Wilson score interval is a widely recommended alternative for small samples and for proportions near the ends of the range. It stays between 0 and 1, and it still gives a range when there are no successes: for 0 of 40 it runs from 0 to 0.0876. The calculator can show the Wald and Wilson intervals side by side, so you can see how much they disagree. When they differ noticeably, the Wilson interval is the more dependable of the two. For large samples with moderate proportions, they are close.

95% intervals for the same counts by two methods. Wald limits are shown exactly as calculated and are not trimmed to the range 0 to 1. Wilson limits always stay within it.
Successes of samplep-hatWald 95% intervalWilson 95% interval
42 of 1200.35000.2647 to 0.43530.2705 to 0.4388
9 of 600.15000.0597 to 0.24030.0810 to 0.2611
1 of 200.0500−0.0455 to 0.1455 (outside 0 to 1)0.0089 to 0.2361
19 of 200.95000.8545 to 1.0455 (outside 0 to 1)0.7639 to 0.9911
0 of 400.00000.0000 to 0.0000 (zero width)0.0000 to 0.0876
40 of 401.00001.0000 to 1.0000 (zero width)0.9124 to 1.0000

Input checks and edge cases

The calculator stops and explains the problem, rather than showing a misleading number, when:

  • x or n is missing, is not a whole number, is negative, or exceeds 1,000,000,000,000;
  • n is 0, because there is no sample to take a proportion of;
  • x is larger than n, because successes cannot outnumber the observations;
  • a custom confidence level is not a number above 0 and below 100. The p-hat result still appears in that case, and a note explains why the interval was skipped.

Zero successes and all-success samples are not errors. They are valid values of p-hat. What changes is how reliable the interval is, and the calculator says so alongside the result.

Assumptions and limitations

  • The calculator treats the data as a random sample of independent observations from the population. It cannot check how the data were collected.
  • The Wald interval is an approximation, and its real coverage can fall well short of the stated level for small samples or extreme proportions. The Wilson interval is more dependable in those cases, although it is also an approximation.
  • The standard error here estimates the variability of p-hat from simple random sampling. It makes no finite-population correction and does not adjust for weighting, clustering or other complex survey designs.
  • Planning a sample size, finding probabilities from the sampling distribution of p-hat and testing a claimed proportion are separate tasks, outside this page. For the margin of error alone, see the Margin of Error Calculator. For sampling distribution probabilities, use the Sampling Distribution of the Sample Proportion Calculator. For a one-proportion z test, try the Z-test Calculator or the Hypothesis Testing Calculator. For a wider range of interval methods, see the Confidence Interval Calculator.
  • This calculator provides a mathematical result from the values you enter. It is an informational and educational tool, not professional or statistical advice, and decisions that matter should be reviewed by a qualified statistician.

Formula sources

The sample proportion, its sampling distribution, the standard error, the Wald interval and the Wilson interval were checked against these independent references:

Frequently asked questions

What is p-hat in statistics?

P-hat is the sample proportion: the share of observations in a sample that have the characteristic you are counting. It is calculated as x divided by n and is used as a point estimate of the population proportion p. Because it comes from one sample, a different sample would usually give a different p-hat.

How do I calculate p-hat from the number of successes and sample size?

Divide the number of successes by the sample size. If 42 of 120 people answered yes, p-hat = 42 / 120 = 0.35, which is 35%. Keep the full division and round only the figure you report.

What do x and n mean in the p-hat formula?

The letter x is the number of successes, meaning the observations that meet your condition, such as yes answers or defective items. The letter n is the total number of observations in the sample. The successes are part of n, so x cannot be larger than n.

What is the difference between p-hat and the population proportion p?

The population proportion p is the true share in the whole population. It is a fixed value that is usually unknown. P-hat is the share in your sample, and it varies from sample to sample. The mean of the sampling distribution of p-hat is p, so p-hat is an unbiased estimator of p, but any single p-hat can sit above or below it.

How do I interpret p-hat as a percentage?

Multiply by 100. A p-hat of 0.35 means 35% of the sample had the characteristic. That statement is about the sample. Saying something about the population needs an interval or a test, because the sample proportion is only an estimate.

How do I calculate q-hat from p-hat?

Subtract p-hat from 1, or divide the number of failures by n. For p-hat = 0.35, q-hat = 1 − 0.35 = 0.65. It is the share of the sample that did not have the characteristic, and p-hat and q-hat always add up to 1.

What is the standard error of p-hat?

It is the estimated standard deviation of p-hat across repeated samples: sqrt(p-hat × q-hat / n). The true standard deviation uses the unknown p, so the estimate substitutes p-hat. For 42 successes in 120, the standard error is 0.0435.

How do I calculate a 95% confidence interval for a population proportion?

With the usual normal-approximation (Wald) method, take p-hat ± 1.96 × the standard error. For 42 of 120 that is 0.35 ± 0.0853, or 0.2647 to 0.4353. The Wilson score interval, 0.2705 to 0.4388 for the same counts, is a better choice for small samples or proportions near 0 or 1. Choose the confidence interval option in the calculator to see both.

How does sample size affect the margin of error?

The margin of error shrinks in proportion to the square root of n, so you need four times the sample to halve it. A larger sample gives a narrower interval around p-hat. It does not remove bias from a sample that was not random.

When can I use the normal approximation for a sample proportion?

When the sample is random and independent, and there are enough successes and failures. The most common rule asks for at least 10 of each, although some courses use 5 and others 15. If you sample without replacement, the sample should also be a small part of the population, often taken as under 10%.

Can p-hat equal 0 or 1, and what happens to the confidence interval?

Yes. Zero successes gives p-hat = 0 and all successes gives p-hat = 1, and both are valid. The Wald standard error is then 0, so its interval has zero width, which is not trustworthy. The Wilson interval still gives a range: for 0 of 40 at 95% it is 0 to 0.0876.

What is the difference between p-hat and a p-value?

They answer different questions. P-hat is a proportion calculated from the sample data. A p-value comes from a hypothesis test and is the probability of a result at least as extreme as the one observed if the null hypothesis were true. A p-hat of 0.35 is not a 35% probability of anything about a hypothesis.