Binomial Distribution Calculator
Most binomial pages answer one question and make you come back for the next one. This one shows the exact count, fewer than, at most, more than, at least and a range from the same two numbers, with the mean, the variance and the standard deviation beside them and the distribution drawn underneath with your counts shaded. The probability can be typed as a decimal, as a percentage like 30%, or as a fraction like 1/6. Whichever tail is the smaller one is added up term by term rather than taken away from 1, which is why a far tail here reads 9.3711e-87 instead of zero, and the binomial coefficient stays in logs the whole way, so 100,000 trials is arithmetic this page can do rather than the NaN a factorial turns into.
The probability of exactly k successes in n trials, which is the one term C(n, k) times p to the k times (1 - p) to the rest.
Probabilities are shown to six decimal places and agree with exact rational arithmetic to within 1e-9. Anything below 0.00001 keeps its digits as an exponent rather than rounding away to zero, and a probability that is certain by definition is written as a plain 1 or 0. P(X = 6) = C(20, 6) * 0.3^6 * 0.7^14
Each bar is the probability of exactly that count. The shaded bar is the one count P(X = 6) covers. The most likely count is 6, at 0.191639.
Worked examples
The cases a binomial question usually starts from. Every figure here is computed by the same code as the answer above, so the examples and the tool can never disagree.
Common questions
- How do I calculate a binomial probability?
- P(X = k) is C(n, k) times p to the power k times (1 - p) to the power n - k: the number of ways k successes can land among n trials, multiplied by the probability of one such arrangement. For 20 trials at p = 0.3 and k = 6 that is C(20, 6) * 0.3^6 * 0.7^14, which comes to 0.191639. The page prints that line with your own numbers in it, under the answer, so a figure typed into the wrong field is easy to spot.
- What is the difference between the binomial PMF and the CDF?
- The PMF is the probability of exactly one count, and the CDF is that count and everything below it added up. At 20 trials with p = 0.3, P(X = 6) is 0.191639 while P(X <= 6) is 0.608010: the second is the seven-term sum from 0 up to 6, and the first is only the last of those terms. Both are on the first screen at once rather than behind a mode switch, because which one a question needs is usually clear only when you can see them side by side.
- How do I find the probability of at least k successes?
- Choose At least, and the page works out the probability of every count from k to n. At 20 trials with p = 0.3, P(X >= 7) is 0.391990. Whenever that side is the smaller of the two it is added up from its largest term outward rather than taken away from 1, which is what keeps a small tail readable: at 100,000 trials with p = 0.005, P(X >= 1000) is 9.3711e-87, a figure one minus the cumulative probability cannot hold at all, because the cumulative side of it has already rounded to 1.
- What are the mean, variance and standard deviation of a binomial distribution?
- The mean is n times p, the variance is n times p times (1 - p), and the standard deviation is the square root of the variance. With 20 trials at p = 0.3 that is a mean of 6, a variance of 4.2 and a standard deviation of 2.0494. All three sit in the readout beside the probability, because the count you are asking about is easier to judge once you know how far it sits from the middle of the distribution.
- Can I enter the probability as a percentage or a fraction?
- Yes. A decimal like 0.3, a percentage like 30% and a fraction like 1/6 are all read, and a percentage or a fraction is echoed back underneath as the p it was read as. Fractions are what dice questions are made of: rolling a six on 10 rolls is p = 1/6, and P(X = 2) is 0.290710. A fraction with zero on the bottom is refused with the reason rather than returned as infinity, and anything outside 0 to 1 is refused with the number it read quoted back.
- How many trials can this handle?
- Up to 100,000, and a figure at that ceiling still agrees with exact rational arithmetic to within 1e-9. The usual limit is the binomial coefficient: 171 factorial is already larger than a double can hold, so a calculator that forms C(n, k) directly returns Infinity or NaN well before n reaches five figures. Here the coefficient stays as a log-gamma factorial and only the finished logarithm is exponentiated, so at 100,000 trials with p = 0.005, P(X = 500) is 0.017883.
- What happens when p is 0 or 1?
- The count stops being random, and the page says so. At p = 0 no trial succeeds, so P(X = 0) is exactly 1 and every other count is exactly 0. At p = 1 every trial succeeds, so all the probability sits on X = n. Those answers come back as an exact 1 or 0 rather than a rounded decimal, and the readout marks them exact, because certainty and a probability that merely rounds to 1 at six decimal places are different things.
- How accurate are the probabilities?
- Every figure agrees with exact rational arithmetic to within 1e-9, which is far tighter than the six decimal places shown. The reference is not another floating-point library: it is the same probability worked out as an integer fraction, C(n, k) times the numerator to the power k, times the denominator minus the numerator to the power of the trials left over, all over the denominator to the power n. Anything below 0.00001 is printed with its digits as an exponent rather than rounded away to a string of zeroes.
- When is the binomial distribution the wrong model?
- When the trial count is not fixed, when the trials affect each other, or when the probability changes from trial to trial. Drawing cards without putting them back is the common case: the chance changes with every draw, so the count follows the hypergeometric distribution rather than this one. The page computes the distribution you describe and nothing else, and it has no opinion about what the number means for whatever you are counting.
Probabilities are computed through log-gamma factorials by jstat 1.9.6, so a large n does not overflow and the far tails stay accurate instead of collapsing to zero. The model assumes a fixed number of independent trials that each share one probability, and p = 0 and p = 1 are returned exactly. It describes a distribution and predicts nothing about whatever you are counting.