01
Hardy-Weinberg equation
p + q = 1
p² + 2pq + q² = 1
p and q are the frequencies of the two alleles, A and a. In a population at equilibrium, p² is the frequency of AA, 2pq of Aa and q² of aa. From counts, p = (2 × AA + Aa) ÷ (2 × N).
02
Worked example: testing equilibrium
A sample of 1,000 people has 298 AA, 489 Aa and 213 aa.
p = (2 × 298 + 489) ÷ 2000 = 0.5425, q = 0.4575
| Genotype | Observed | Expected |
|---|---|---|
| AA | 298 | 294.31 |
| Aa | 489 | 496.39 |
| aa | 213 | 209.31 |
Chi-square = 0.221 with 1 degree of freedom, p = 0.638. The counts are consistent with Hardy-Weinberg equilibrium.
03
Worked example: carrier frequency
A recessive condition affects 4% of a population, so q² = 0.04.
q = √0.04 = 0.2, p = 0.8
carriers: 2pq = 2 × 0.8 × 0.2 = 0.32
About 32% of the population carries one copy of the allele.
04
Assumptions
The equation holds for a large, randomly mating population with no selection, mutation or migration at the locus. A significant chi-square says the counts do not fit those proportions; it does not say which assumption failed. In genotyping studies a departure is often a sign of genotyping error. The test has 1 degree of freedom: three genotype classes, minus one, minus one allele frequency estimated from the data.
05
Common mistakes with Hardy-Weinberg
- Using 2 degrees of freedom. The worked example’s chi-square of 0.221 gives p = 0.638 with the correct 1 degree of freedom; with 2 it would be 0.895. One degree is lost for estimating p from the data.
- Taking the affected fraction as q. If 4% are affected, q² = 0.04 and q = 0.2, giving 32% carriers. Treating 0.04 as q gives 7.7% carriers, a quarter of the real figure.
- Counting alleles from one genotype. p is (2 × AA + Aa) ÷ 2N = 0.5425 in the worked example; the AA fraction alone, 0.298, is not an allele frequency.
- Testing a rare allele with chi-square. With 980 AA, 20 Aa and 0 aa the expected aa count is 0.1, far below the usual minimum of 5, so the chi-square p value of 0.749 is not reliable; an exact test is better.
Trust
How this page is checked
- The calculation runs on code with automated tests against worked reference values. Every number in the examples on this page was produced by that same code, not typed by hand.
- The formulas and conventions used are stated on the page, so you can reproduce the result yourself or compare it with your own software.
- Last reviewed by the Sciloom team, Zebra Nine Studio Inc. It is a tool for research and teaching, not a substitute for a statistician, a validated lab method or medical advice.
Cite this page
Sciloom. (2026). Hardy-Weinberg calculator. Zebra Nine Studio Inc. https://sciloom.si/hardy-weinberg-calculator
Frequently asked questions
How do I calculate allele frequencies from genotype counts?
Count alleles: each AA carries two A alleles and each Aa carries one. p = (2 × AA + Aa) ÷ (2 × total), and q = 1 − p.
How do I find the carrier frequency?
Take the square root of the frequency of the recessive phenotype to get q, then compute 2pq. If 1 in 2,500 is affected, q = 0.02, p = 0.98 and 2pq = 0.0392, about 1 in 26.
Why 1 degree of freedom and not 2?
There are three genotype classes, which would give 2, but one more is lost because the allele frequency is estimated from the same data.
What if an expected count is below 5?
The chi-square approximation becomes unreliable, which is common when one allele is rare. Use an exact test for Hardy-Weinberg proportions instead. The calculator warns you when this happens.