Hardy-Weinberg and Genetic Drift

Simulate allele frequencies across generations and see how population size and selection break equilibrium

Intermediate
100

Diploid individuals, so 2N allele copies

0.50
100
10

Selection

Generation
0 / 100
p in population 1
0.500
Mean p
0.500
Infinite population p
0.500
Fixed (p = 1)
0 of 10
Lost (p = 0)
0 of 10
Mean 2pq
0.500
Expected 2pq (drift)
0.500
  • Population 1 (selected; tap a line to pick another)
  • Starting frequency: an infinite population would stay here

Population 1, generation 0: observed genotypes against Hardy-Weinberg p², 2pq, q² for p = 0.500

Generation 0 is the founding population. Run or step forward to breed offspring by random mating.

Bars: observed genotype shares. Black ticks: Hardy-Weinberg expectation from this generation's allele frequency. Fitness: AA 1.000, Aa 1.000, aa 1.000.

Hardy-Weinberg equilibrium and what breaks it

Take one gene with two alleles, A with frequency p and a with frequency q = 1 − p. If individuals mate at random, two random gametes meet in every offspring, so the genotype frequencies are AA = p², Aa = 2pq and aa = q². This is the Hardy-Weinberg principle: in a very large population with random mating and no selection, mutation or migration, allele and genotype frequencies stay the same from one generation to the next.

Real populations are finite. The visualizer uses the Wright-Fisher model: each generation of N diploid individuals is formed by drawing 2N allele copies at random from the previous generation, after selection has acted. The sampling makes p take a random walk called genetic drift. Once p reaches 0 or 1 the allele is lost or fixed and, with no mutation, it stays there.

Selection adds a steady push. When aa individuals survive less well, A rises every generation. When heterozygotes are fittest, both alleles are held at a stable balance.

Random mating

Gametes combine at random, so genotype frequencies follow p², 2pq and q² after a single generation.

Genetic drift

Each generation is a finite random sample of the last. Allele frequencies wander by chance, faster in small populations.

Natural selection

When genotypes differ in survival or reproduction, the fitter alleles rise in frequency in a steady, predictable direction.

Population size

Drift scales with 1/(2N). In large populations selection dominates; in small ones chance can override even strong selection.

Key formulas

Hardy-Weinberg proportions

p² + 2pq + q² = 1

p
frequency of allele A
q
frequency of allele a, so p + q = 1

Allele frequency from genotype counts

p = (2 × N_AA + N_Aa) / (2N)

N
number of diploid individuals

Genetic drift in one generation

E[p′] = p,   Var(p′) = p(1 − p) / (2N)

Loss of heterozygosity and fixation under drift

H_t = H_0 (1 − 1/(2N))ᵗ,   P(A fixes) = p_0

H
heterozygosity 2pq, averaged over many populations

Selection

p′ = (p² w_AA + pq w_Aa) / w̄,   w̄ = p² w_AA + 2pq w_Aa + q² w_aa

w
relative fitness of each genotype
w̄
mean fitness of the population

Heterozygote advantage

p̂ = t / (s + t)

s, t
fitness costs, with fitnesses AA = 1 − s, Aa = 1 and aa = 1 − t

Worked example: cystic fibrosis carriers

Cystic fibrosis is recessive. In populations of northern European descent about 1 baby in 2,500 is affected. Assuming Hardy-Weinberg proportions, how common are carriers?

Carriers are about 98 times as common as affected people, because most copies of a rare recessive allele sit in heterozygotes.

QuantityFormulaValue
Affected (aa)q²1/2,500 = 0.0004
Frequency of aq = √0.00040.02
Frequency of Ap = 1 − q0.98
Carriers (Aa)2pq0.0392, about 1 in 26
Not carrying a (AA)p²0.9604

The same fact explains why selection against a rare recessive is slow: aa individuals are so rare that selection barely touches the a allele, which is what the flattening curve in the selection step of the tour shows.

How to use this visualizer

  1. 1
    Set the population size N, the starting frequency p of allele A, the number of generations and how many replicate populations to run side by side.
  2. 2
    Press Run to breed generation after generation. Each coloured line is one population; the dashed line is what an infinite population would do.
  3. 3
    Tap a line to select that population. The bars below compare its observed AA, Aa and aa shares with p², 2pq and q² for the current generation.
  4. 4
    Watch the Fixed and Lost counts, and compare Mean 2pq with Expected 2pq (drift) to see heterozygosity drain away.
  5. 5
    Turn on selection against aa, or set custom fitnesses, and compare small and large N.

Real-world applications

Carrier frequencies

From how common a recessive disease is, Hardy-Weinberg estimates how many people carry one copy of the allele without showing it.

Conservation genetics

Small, isolated populations such as cheetahs or island foxes lose genetic diversity to drift, which conservation plans try to slow.

Sickle-cell and malaria

Heterozygote advantage keeps the sickle-cell allele common where malaria is widespread, as the overdominance setting shows.

Founder effects

A few founders carry a random sample of alleles, so rare variants can become common, as in some isolated communities.

Equilibrium is a null model

Hardy-Weinberg is a baseline, not a claim that real populations are unchanging. A population can show p², 2pq and q² genotype proportions in every generation while its allele frequency drifts or is pushed by selection, because random mating restores the proportions each generation from whatever p currently is.

Practice problems

Problem 1: From phenotype to genotypes

In a population in Hardy-Weinberg equilibrium, 16% of individuals show a recessive trait. What are p and q, and what fraction of the population are carriers?
Show solution

q² = 0.16, so q = 0.4

p = 1 − 0.4 = 0.6

Carriers: 2pq = 2 × 0.6 × 0.4 = 0.48

Homozygous dominant: p² = 0.36

p = 0.6, q = 0.4; 48% are carriers

Problem 2: Drift erodes diversity

Many populations of N = 50 start with p = 0.5 and evolve neutrally. What is the expected heterozygosity 2pq after 50 generations?
Show solution

H_0 = 2 × 0.5 × 0.5 = 0.5

1 − 1/(2N) = 1 − 1/100 = 0.99

H_50 = 0.5 × 0.99⁵⁰ = 0.5 × 0.605 = 0.302

About 0.302, so roughly 40% of the heterozygosity is gone

Problem 3: One generation of selection

A large population has p = 0.5. The fitnesses are AA = 1, Aa = 1 and aa = 0.8. What is the frequency of A in the next generation?
Show solution

w̄ = 0.25 × 1 + 0.5 × 1 + 0.25 × 0.8 = 0.95

p′ = (p² w_AA + pq w_Aa) / w̄ = (0.25 + 0.25) / 0.95

p′ ≈ 0.526, a rise of about 0.026 in one generation

Spotted a mistake on this page?

Wrong formula, broken animation or confusing wording. Tell us and we will fix it.