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

Sampling With Replacement: Formula and Example

Sampling with replacement returns each unit before the next draw. See the N^n formula, a worked urn example, and R, Python and Excel code.

Written and maintained by CASRAI Editorial Board

Last updated

Sampling with replacement means that each unit you draw is put back before the next draw, so the same unit can be selected more than once. Every draw is made from the same full population, which makes the draws independent. This guide gives the definition, the counting formula, a worked example with the arithmetic shown, the contrast with sampling without replacement, and the code for R, Python and Excel. One point is worth knowing up front: base R’s sample() samples without replacement unless you ask otherwise.

What is sampling with replacement?

In sampling with replacement, a unit is selected, recorded and returned to the population before the next unit is selected. Because the population never shrinks, the chance of selecting any particular unit is the same on every draw, and the outcome of one draw tells you nothing about the next. A unit may appear several times in the sample, or not at all. Sampling without replacement is the opposite scheme: a selected unit is not returned, so it can appear at most once. For the standard survey version of that scheme, see simple random sampling.

Formula: how many samples are possible?

Let N be the number of units in the population and n the number of draws. Each draw has N possible outcomes, and the draws do not restrict one another, so:

  • Ordered samples with replacement: Nn
  • Ordered samples without replacement: N! / (N − n)! = N × (N − 1) × … × (N − n + 1)
  • Probability that a specific unit is chosen on any one draw with replacement: 1 / N
  • Probability that a specific unit is never chosen in n draws with replacement: (1 − 1/N)n

Here N is the population size, n is the sample size (number of draws), and the exclamation mark denotes the factorial. For N = 3 units A, B and C and n = 2 draws, with replacement gives 32 = 9 ordered samples (AA, AB, AC, BA, BB, BC, CA, CB, CC), while without replacement gives 3 × 2 = 6 (the three repeated pairs AA, BB and CC are impossible).

Worked example: two reds from an urn of 10

An urn holds 5 red and 5 blue marbles. You draw two and want the probability that both are red.

  1. With replacement: the first draw is red with probability 5/10 = 0.5. The marble goes back, so the second draw is again 5/10 = 0.5. Because the draws are independent, P(two reds) = 0.5 × 0.5 = 0.25.
  2. Without replacement: the first draw is red with probability 5/10. With one red removed, 4 reds remain among 9 marbles, so the second draw is 4/9. P(two reds) = 5/10 × 4/9 = 20/90 = 0.2222.

The two answers differ because removing a red marble makes a second red less likely. With replacement the result is a simple product, which is why it leads to the binomial model; without replacement the count of reds follows the hypergeometric distribution.

Sampling with replacement vs without replacement

Feature With replacement Without replacement
Can a unit appear twice? Yes No
Draws independent? Yes No
Ordered samples (N = 3, n = 2) 9 6
P(two reds), 5 red and 5 blue, n = 2 0.25 0.2222
Variance of the sample mean, population 2, 4, 6, 8 with n = 2 2.5 1.6667

The last row comes from enumerating every sample. The population 2, 4, 6, 8 has mean 5 and population variance σ² = (9 + 1 + 1 + 9) / 4 = 5. With replacement there are 16 ordered samples of size 2, and the variance of their means is σ² / n = 5 / 2 = 2.5. Without replacement there are 12 ordered samples, and the variance of their means is (σ² / n) × (N − n) / (N − 1) = 2.5 × 2/3 = 1.6667. The factor (N − n) / (N − 1) is the finite population correction; it approaches 1 when n is small relative to N, which is why the two schemes give almost the same answers for large populations. That is the reasoning behind the sample-size rule discussed in the 10% condition.

Interpretation: what the result means

What you see How to read it
A unit appears twice in the sample Expected under replacement; it is not an error and not a duplicate record.
Sample is larger than the population Possible only with replacement (for example 12 draws from 10 units).
Some population units never appear Expected: with n = N = 10, each unit is missing with probability 0.910 = 0.3487, so about 65% of units (1 − 0.3487 = 0.6513) appear at least once.
Results differ slightly from a without-replacement run Expected when the sample is a large share of the population; negligible when it is a small share.

The missing-unit figure matters for the bootstrap. The NIST/SEMATECH e-Handbook describes a bootstrap subsample as generated “with replacement so that any data point can be sampled multiple times or not sampled at all.” As n grows with N = n, (1 − 1/n)n tends to 0.3679 (the value of 1/e): at n = 10 it is 0.3487, at n = 100 it is 0.3660 and at n = 1,000 it is 0.3677. So a bootstrap resample typically contains about 63% of the distinct original observations. See bootstrapping in statistics for how this is used.

Assumptions and common mistakes

  • Assuming software samples with replacement by default. R’s sample(x, size, replace = FALSE, prob = NULL) defaults to replace = FALSE. Python’s random.sample() is documented as “random sampling without replacement”, while random.choices() returns a list chosen “with replacement”. Choosing the wrong function changes the scheme silently.
  • Using the without-replacement formula for with-replacement draws (5/10 × 4/9 instead of 5/10 × 5/10), or the reverse.
  • Treating without-replacement draws as independent. They are not, although the dependence is slight when the sample is a small fraction of the population.
  • Not reporting the scheme. A reader cannot reproduce or evaluate the analysis if the method states only that a random sample was taken.
  • Counting repeated units as independent people. If a person can be drawn twice, the sample contains fewer distinct people than draws.

How to report it

State the scheme, the population, the sample size and the software. An example for a methods section: “We drew 1,000 bootstrap resamples, each of size n = 120, by sampling observations with replacement from the original data (R, sample() with replace = TRUE, seed 2026).” Report the seed so the draw can be repeated, and report the number of draws, which is separate from the sample size. If your journal or department follows APA style, check the current edition for how to format statistical symbols and numbers in the same sentence.

How to sample with replacement in R, Python or Excel

R

set.seed(2026)
x = c(2, 4, 6, 8)
sample(x, size = 6, replace = TRUE)   # with replacement; size may exceed length(x)
sample(x, size = 4)                   # replace = FALSE by default: without replacement

For random numbers more generally, see random number generation in R.

Python

import random
random.seed(2026)
pop = [2, 4, 6, 8]
random.choices(pop, k=6)   # with replacement
random.sample(pop, k=4)    # without replacement (unique positions)

Excel

Put the population in A2:A11 and fill this formula down as many rows as you have draws: =INDEX($A$2:$A$11, RANDBETWEEN(1, 10)). Each row picks a position from 1 to 10 independently of the other rows, so the same unit can be chosen again, which is sampling with replacement. The values change on every recalculation, so copy and paste them as values to freeze a sample.

Frequently asked questions

Can the same unit be selected twice?

Yes, with replacement. After each draw the unit goes back into the population, so it can be drawn again on any later draw.

Do the draws stay independent?

Yes. The population is identical at every draw, so the probability of each outcome is unchanged by earlier draws. Without replacement the draws are dependent, as the 5/10 × 4/9 calculation above shows.

Is sampling with replacement the same as the bootstrap?

No, but the bootstrap relies on it. A bootstrap resample is a sample of the same size as the data drawn with replacement from the data itself. Sampling with replacement is the general scheme; the bootstrap is one use of it. The bootstrap in R guide shows the code.

Which scheme do surveys use?

Surveys usually sample without replacement, because interviewing the same person twice adds no new information. The with-replacement model is still used as a simplifying approximation when the sample is a small share of the population, and it underlies the binomial experiment.

When does the difference between the two schemes stop mattering?

When n is small relative to N. The finite population correction (N − n) / (N − 1) is then close to 1. In the example above, with N = 4 and n = 2 it is 2/3, which is a large correction; with N = 1,000 and n = 10 it is 990/999 = 0.991.

Sources

Follow CASRAI

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

Ask CASRAI · free to try

Ask about Sampling With Replacement: Formula and 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.