Skip to main content
v2026.11,858 entries · CC-BY 4.0

Bernoulli Distribution Formula: Mean, Variance, Example

The Bernoulli distribution formula P(X=x)=p^x(1-p)^(1-x), with mean p, variance p(1-p), a worked example and code.

Written and maintained by CASRAI Editorial Board

Last updated

The Bernoulli distribution formula is P(X = x) = px(1 − p)1−x for x = 0 or 1, with mean p and variance p(1 − p). This guide defines every symbol, works one example through with the arithmetic shown, and gives the same calculation in Excel, R and Python so you can check your own numbers.

What is the Bernoulli distribution?

The Bernoulli distribution is a discrete probability distribution with only two possible values for the random variable (MathWorks, Statistics Toolbox documentation). By convention the two values are coded 1 (“success”) and 0 (“failure”). The distribution has a single parameter, p, the probability of success, with 0 ≤ p ≤ 1. It describes one trial: one coin flip, one yes/no survey answer, one pass/fail test. A random variable that follows it is often written X ~ Bernoulli(p).

The Bernoulli distribution formula

The probability mass function gives 1 − p when x = 0 and p when x = 1 (SciPy and MathWorks documentation). Written as a single expression:

P(X = x) = px (1 − p)1 − x, for x in {0, 1}

  • X: the random variable, which can only take the value 0 or 1.
  • x: the particular value you ask about.
  • p: the probability that X = 1 (success). It is the only parameter.
  • 1 − p: the probability that X = 0 (failure). The two probabilities always sum to 1.

Setting x = 1 makes the second factor equal 1 and leaves p. Setting x = 0 makes the first factor equal 1 and leaves 1 − p. That is the whole trick behind the compact form. See also the general probability mass function formula.

Mean and variance

The mean of the Bernoulli distribution is p, and its variance is p(1 − p) (MathWorks). The standard deviation is the square root of the variance, √(p(1 − p)). The Bernoulli distribution is a special case of the binomial distribution with N = 1 (MathWorks).

Worked example with real numbers

This is an illustrative example with made-up data, not a real study. Suppose 40 survey respondents each answer one yes/no question, and 12 answer yes. Code yes as 1 and no as 0. Treat each answer as one Bernoulli trial with the same p.

  1. Estimate p. The sample proportion is 12 / 40 = 0.30. Call it p̂ = 0.30.
  2. Probabilities. P(X = 1) = 0.301 × 0.700 = 0.30. P(X = 0) = 0.300 × 0.701 = 0.70. Check: 0.30 + 0.70 = 1.
  3. Mean. E(X) = p = 0.30.
  4. Variance. p(1 − p) = 0.30 × 0.70 = 0.21.
  5. Standard deviation. √0.21 = 0.4583 (rounded to four decimals).
  6. Standard error of the proportion. For n independent trials, √(p(1 − p) / n) = √(0.21 / 40) = √0.00525 = 0.0725.
  7. Approximate 95% interval (Wald). 0.30 ± 1.96 × 0.0725 = 0.30 ± 0.142, which is 0.158 to 0.442.

Bernoulli distribution examples

  • A single fair coin flip: p = 0.5, so the mean is 0.5 and the variance is 0.25.
  • One participant passes (1) or fails (0) a screening test.
  • One manuscript is accepted (1) or rejected (0) on first submission.
  • One sampled item from a production line is defective (1) or not (0).

In each case you observe one outcome with two possibilities. When you count the successes across several independent, identical trials, you move to the binomial distribution; the page Bernoulli vs binomial distribution sets the two side by side.

Interpretation: what the result means

Because the variance is p(1 − p), it is largest when p = 0.5 and shrinks toward 0 as p approaches 0 or 1. The values below are computed directly from that formula.

p Mean Variance p(1 − p) Standard deviation
0.10 0.10 0.09 0.300
0.30 0.30 0.21 0.458
0.50 0.50 0.25 0.500
0.70 0.70 0.21 0.458
0.90 0.90 0.09 0.300

Two readings follow. First, the mean of a Bernoulli variable is the probability itself, so the average of many 0/1 codes is a proportion. Second, p and 1 − p give the same variance: coding success as 0 and failure as 1 changes the mean to 1 − p but not the spread.

Assumptions and common mistakes

  • Exactly two outcomes. If the response has three or more categories, the Bernoulli model does not apply to the original variable; you can only use it after collapsing to “one category versus all others”.
  • Fixed p. The probability of success must be the same for the trial you model. If p differs across people or conditions, a single Bernoulli(p) hides that difference.
  • Independence when you combine trials. The standard error formula above and the binomial count both assume the trials are independent. Repeated answers from the same person are not.
  • Confusing the pmf with the sample. p is a parameter; 0.30 in the example is an estimate from 40 answers, and a different sample gives a different estimate.
  • Using the normal interval at extremes. The Wald interval above is an approximation and behaves poorly when p̂ is near 0 or 1 or n is small.

How to report it (APA example)

The sentence below is an illustration built from the worked example, showing the elements worth reporting: counts, the proportion, and an interval. Follow the style manual your journal or institution requires for number formatting.

Of the 40 respondents, 12 (30%) answered yes (p̂ = .30, 95% CI [.16, .44]).

Report n, the count of successes and the estimated proportion. If you also give a variance, state that it is p̂(1 − p̂) = 0.21.

How to calculate it in Excel, R or Python

Excel

=BINOM.DIST(1, 1, 0.3, FALSE)   returns 0.3  (P(X = 1))
=BINOM.DIST(0, 1, 0.3, FALSE)   returns 0.7  (P(X = 0))
=0.3*(1-0.3)                    returns 0.21 (variance)

This uses the binomial function with one trial, which is the Bernoulli case (the Bernoulli distribution is the binomial with N = 1).

R

p <- 0.3
dbinom(c(0, 1), size = 1, prob = p)   # 0.7 0.3
p * (1 - p)                          # variance 0.21
rbinom(10, size = 1, prob = p)       # 10 random Bernoulli draws

The R manual documents dbinom (density) and rbinom (random deviates) for the binomial family; size = 1 gives the single-trial case.

Python

from scipy.stats import bernoulli
p = 0.3
bernoulli.pmf([0, 1], p)   # array([0.7, 0.3])
bernoulli.mean(p)          # 0.3
bernoulli.var(p)           # 0.21

SciPy provides bernoulli.pmf(k, p), bernoulli.mean(p), bernoulli.var(p) and bernoulli.stats(p, moments='mvsk').

FAQ

What is the Bernoulli distribution?

It is the probability distribution of a single trial with two outcomes, coded 1 and 0, where 1 occurs with probability p and 0 with probability 1 − p.

What is the formula for the mean and variance of a Bernoulli distribution?

The mean is p and the variance is p(1 − p).

How is it related to the binomial distribution?

The Bernoulli distribution is the binomial distribution with a single trial (N = 1). A binomial count is the sum of independent Bernoulli outcomes; see binomial distribution expected value and the binomial probability calculator guide. For the number of Bernoulli trials needed to reach a set number of successes, see the negative binomial distribution.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Bernoulli Distribution Formula: Mean, Variance, Example

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.