Tabellab
Data, tech, science & health

The Hardy-Weinberg equation in Excel, with worked examples

The Hardy-Weinberg equation, p² + 2pq + q² = 1, gives the genotype frequencies you expect in a population that is not evolving: p and q are the frequencies of the two alleles of a gene, p² and q² the two homozygotes and 2pq the heterozygotes. This guide turns it into a small Excel calculator. From 400 people typed for the MN blood group it finds p = 0.55 and q = 0.45, compares the observed genotypes with the expected 121, 198 and 81 in a chi-square test, and then estimates the carrier frequency of a recessive condition from its incidence: 1.98%, about 1 person in 50.

Updated 21 Oct 2026 5 min read By Tabellab team

The two Hardy-Weinberg equations

p + q = 1 for the alleles, and p² + 2pq + q² = 1 for the genotypes.

The second equation is simply (p + q)² written out. If a population mates at random, an individual gets one allele from each parent, so the chance of two M alleles is p × p, of two N alleles q × q, and of one of each 2pq, because the M can come from either parent. The equations hold only under the Hardy-Weinberg conditions: random mating, no selection, no mutation, no migration and a population large enough that chance (genetic drift) does not shift the frequencies.

Step 1: allele frequencies from genotype counts

When heterozygotes can be told apart, as in the codominant MN blood group, count alleles directly. Each person carries two alleles, so 400 people carry 800. MM people carry two M alleles and MN people one:

p = (2 × MM + MN) ÷ 2n = (2 × 128 + 184) ÷ 800 = 0.55, and q = 1 − p = 0.45.

Step 2: expected genotype frequencies and counts

Under Hardy-Weinberg, MM should make up p² = 0.3025 of the population, MN 2pq = 0.4950 and NN q² = 0.2025. The three always add up to 1, which is a quick check of the formulas. Multiplied by 400 people, the expected counts are 121, 198 and 81, against 128, 184 and 88 observed. There are slightly fewer heterozygotes than expected. Is that chance, or a sign that the population is not in equilibrium?

Worked example: MN blood group and a recessive condition

Observed genotype counts and the incidence are inputs (yellow). Rows 2 to 5 compare observed with expected genotypes, rows 8 to 14 hold the allele frequencies and the test, rows 17 to 22 the carrier estimate. The sample is illustrative.

Worked example: MN blood group and a recessive condition
ABCDE
1GenotypeObservedExpected freq.Expected count(O − E)² ÷ E
2MM1280.3025121.00.405
3MN1840.4950198.00.990
4NN880.202581.00.605
5Total4001.0000400.02.000
6
7Allele frequencies and testValue
8Alleles in the sample (2n)800
9p = frequency of M0.550
10q = frequency of N0.450
11χ² statistic2.000
12Degrees of freedom (3 − 1 − 1)1
13p-value0.157
14Critical value at α = 0.053.841
15
16Recessive conditionValue
17Affected newborns: 1 in10,000
18q² = incidence0.0001
19q = SQRT(q²)0.010
20p = 1 − q0.990
21Carrier frequency 2pq1.98%
22Carriers: 1 in50.5
Key formulas
  • B9=(2*B2+B3)/B8p from allele counts
  • C3=2*B9*B10Heterozygote frequency 2pq
  • B13=CHISQ.DIST.RT(B11,B12)p-value with df = 1
  • B21=2*B20*B19Carrier frequency 2pq

Educational example with illustrative numbers, not medical or genetic-counselling advice.

Step 3: a chi-square test

For each genotype, calculate (observed − expected)² ÷ expected and add them up: 0.405 + 0.990 + 0.605 gives χ² = 2.000. The degrees of freedom are not 3 − 1 = 2 here: one more is lost because p was estimated from the same data, so df = 3 − 1 − 1 = 1. Then =CHISQ.DIST.RT(2.000,1) returns a p-value of 0.157. That is above 0.05, and χ² is below the critical value of 3.841, so the data are consistent with Hardy-Weinberg equilibrium. That does not prove equilibrium. It only means the deviation is small enough to be chance.

Step 4: carrier frequency of a recessive condition

With a recessive condition you cannot see carriers, but you can count affected people, who are the q² group. If a condition affects 1 in 10,000 newborns, then q² = 0.0001 and q = SQRT(0.0001) = 0.01. So p = 0.99 and the carrier frequency is 2pq = 2 × 0.99 × 0.01 = 1.98%, about 1 in 50.5 people. A condition that looks very rare is carried by around 200 times as many people as it affects. This estimate assumes equilibrium, which close relatives marrying or strong selection can break.

When the dominant phenotype hides the heterozygotes

With complete dominance, AA and Aa look the same, so you cannot count alleles directly. Start from the recessive phenotype instead: its share is q², so q = √(share), and then p = 1 − q, as in step 4. This is the usual route in exam questions such as "16% of a population shows the recessive trait": q² = 0.16, q = 0.4, p = 0.6, and 2pq = 48% are heterozygous.

Common mistakes

  • Counting people instead of alleles. p is a share of alleles, so divide by 2n, and count heterozygotes once and homozygotes twice.
  • Using 2pq as "two times p". 2pq is 2 × p × q. In Excel write =2*B9*B10.
  • Taking q as the recessive phenotype share. The share of affected individuals is q², so q is its square root.
  • Wrong degrees of freedom. With three genotypes and p estimated from the data, df = 1, not 2. With df = 2 the p-value is too large.
  • Percentages in the chi-square test. Use counts, never percentages, and make sure every expected count is at least 5.
  • Reading a large p-value as proof. Not rejecting Hardy-Weinberg only means the data do not show a clear deviation.

Frequently asked questions

What do p and q mean in the Hardy-Weinberg equation?

p is the frequency of one allele of a gene in the population and q the frequency of the other. With two alleles, p + q = 1.

How do you calculate the carrier frequency with Hardy-Weinberg?

Take the share of affected individuals as q², find q with the square root, set p = 1 − q and calculate 2pq. For an incidence of 1 in 10,000, q = 0.01 and 2pq is about 2%.

What are the five Hardy-Weinberg conditions?

Random mating, no natural selection, no mutation, no migration (gene flow) and a very large population, so that genetic drift is negligible.

How do you test whether a population is in Hardy-Weinberg equilibrium?

Compare the observed genotype counts with the expected p², 2pq and q² counts in a chi-square test with one degree of freedom for a gene with two alleles. A p-value below 0.05 suggests the population is not in equilibrium.

Practise it in a lab

Related guides

Reading is step one. Doing is step two.

Every guide links to a lab where you build the same calculation in an online spreadsheet and get instant feedback.

Open the lab