Hardy-Weinberg Calculator
Hardy-Weinberg is a squaring rule: if an allele has frequency q, then q² of the people carry two copies of it, 2pq carry one, and p² carry none. This calculator runs that rule in both directions — from genotype counts to allele frequencies and a significance test, or from a disease rate back to the allele and carrier frequency behind it — and adds the four things the usual Hardy-Weinberg pages leave out: the inbreeding coefficient F = 1 − Ho/He, the exact conditional test for small or rare samples, a 95% interval on the estimate, and separate arithmetic for X-linked loci, dominant traits and the risk carried by a randomly chosen couple.
The principle is a statement about what a population looks like after one generation of random mating, not about what a family looks like. Count the alleles at one locus in a large, intermarrying group and the genotype classes come out of the expansion of (p + q)²: p² homozygotes for the first allele, 2pq heterozygotes, q² homozygotes for the second. The heterozygote gets the factor of two because there are two ways to be one — the allele can arrive from either parent — and that factor is the whole reason a rare recessive disease is mostly carried by healthy people rather than seen in affected ones.
Run the same equation backward and it becomes an epidemiology tool. A condition that appears in 1 birth in 10,000 is q² = 0.0001, so q = 1% and carriers are 2pq = 1.98% of the population — roughly one person in fifty. Nobody counted those carriers; the squaring rule inferred them from the disease rate, which is exactly why carrier-frequency screening numbers look so surprising when you first meet them.
The third thing the equation does is act as a null hypothesis. If a sample of people is typed and the classes match p² : 2pq : q², the population behaves as if it is large, intermarrying and free of selection at that locus. If they do not match, one of those assumptions has failed, and the deviation has a direction: missing heterozygotes (a positive inbreeding coefficient, F) points at relatives mating or at two subpopulations being typed as one, while an excess points at heterozygote advantage or at the wrong alleles having been scored. The chi-square says how far the sample is from the expectation; it cannot say which assumption broke.
How much trust to put in that chi-square depends on the sample, and this is where most online calculators stop. With 15 people the expected count in the rare homozygote class can drop below 5, at which point the chi-square approximation is no longer good, so this page also computes the exact conditional test on the heterozygote count and the sample size the locus needs before either test means anything. A single-locus, two-allele question about relatives and their children is a different intent, and it belongs to the Punnett square calculator; the Hardy-Weinberg guide walks the arithmetic step by step.
Hardy-Weinberg Calculator
How to use the hardy-weinberg calculator
Choose what you have: genotype counts from a sample, allele frequencies, a disease or trait rate, an X-linked rate measured in one sex, or a carrier frequency you want couple risk from.
For counts, type the number of people in each class (never percentages), and switch alleles counted to three when every class is visible — a codominant marker or an ABO-type locus, which gives six classes.
For a trait rate, set how the trait is inherited first. A recessive condition puts the affected in q²; a fully penetrant dominant one puts them in p² + 2pq, and the two solve to very different allele frequencies from the same 19%.
For an X-linked locus, name the sex that was measured: male rates equal q directly, female rates equal q² and need the square root.
Read the primary card — the test p-value in counts mode, the carrier frequency in rate mode — then the genotype table, which pairs every observed class with the count the squaring rule expects.
Check the notes underneath before quoting anything: they give F with its sign, the 95% interval on the allele frequency, the carrier interval that interval implies, and the minimum sample size at which the expected counts reach 5.
Press Calculate. Everything runs in your browser, and the method card states which assumption each figure rests on.
Hardy-Weinberg formula
Variables and units
| Symbol | Meaning | Unit |
|---|---|---|
| N | Individuals typed in the sample | people |
| nAA, nAa, naa | People counted in each genotype class | people |
| p, q | Frequencies of the two alleles, p + q = 1 | % |
| pᵢ | Frequency of allele i at a multi-allele locus | % |
| Ho | Observed heterozygote fraction, nAa / N | % |
| He | Expected heterozygosity, 1 − Σpᵢ² | % |
| F | Heterozygote deficit relative to expectation; 0 at equilibrium | — |
| χ² | Sum of squared observed-minus-expected gaps, scaled by expectation | — |
| df | Genotype classes minus the allele frequencies estimated from the same data | — |
| C | Carrier frequency, 2pq | % |
How hardy-weinberg is calculated
- Count alleles, not people: 2N of them, with each homozygote contributing two and each heterozygote one.
- Square the allele frequencies to get the classes the population would show at equilibrium, and multiply by N to get expected headcounts.
- Subtract: (O − E)² / E summed over classes is the chi-square statistic, judged against df = classes − alleles.
- Report the heterozygote gap as F = 1 − Ho/He, keeping the sign, because the direction names the kind of assumption that failed.
- Bound the estimate: Wilson score interval on q̂ over 2N alleles, carried through 2q(1−q) for the carrier frequency.
- If any expected count is below 5, read the exact conditional test on the heterozygote count and the minimum sample size instead of leaning on the chi-square.
- For a rate entered instead of counts, take the square root in the right direction — q from q² when recessive, q from the unaffected fraction when dominant — then derive carriers as 2pq.
Worked laboratory examples
Example 1 — A sample that just fails the test
Given: 100 people typed: 60 AA, 30 Aa, 10 aa · two alleles
- Alleles: 200 in total, 150 A (2·60 + 30) and 50 a, so p̂ = 75% and q̂ = 25%.
- Expected at equilibrium: 56.25 AA, 37.5 Aa, 6.25 aa — the sample has 7.5 fewer heterozygotes than the squaring rule wants.
- χ² = 4 at 1 degree of freedom gives p = 4.55%, and the exact test on the same table gives 5.89%: a marginal failure either way.
- F = 1 − 30/37.5 = 0.2, a 20% heterozygote deficit, and q̂ sits in a 95% interval of 19.51–31.43%, which is a carrier range of 31.40–43.11%.
Result: p 75% / q 25%; χ² 4 (p = 4.55%), exact p = 5.89%, F = 0.2
Example 2 — Too few people to test at all
Given: 15 people typed: 7 AA, 6 Aa, 2 aa
- p̂ = 66.67% and q̂ = 33.33%, so the expected aa count is 1.67 people.
- That is below 5, so the chi-square (χ² = 0.15, p = 69.85%) is measuring the approximation rather than the population; the exact test returns p = 100% and says nothing can be concluded.
- The engine reports the sample the locus needs: 45 people before the rarest expected class reaches 5.
Result: Not testable at N = 15; 45 people needed for expected counts of 5
Example 3 — A rare recessive disease, read backward
Given: incidence 1 in 10,000 births · recessive, fully penetrant
- Affected = q² = 0.01%, so q = √0.0001 = 1%.
- Carriers = 2pq = 1.98% of everybody — about one person in 50.5, and every one of them healthy.
- Among people without the disease the same carriers are 2q/(1 + q) = 1.9802%; the difference is tiny here and matters more for common recessive conditions.
Result: q = 1%; carriers 1.98% (1 in 50.5)
Example 4 — The same 19%, read as dominant
Given: 19% of a population shows the trait · fully penetrant dominant allele
- The affected are p² + 2pq = 1 − q², so q = √(1 − 0.19) = 0.9 and p = 10%.
- Expected classes: 1% homozygous dominant, 18% heterozygous, 81% unaffected — so most affected people are heterozygotes, which is why dominant conditions rarely appear in their homozygous form.
- Read the same 19% as recessive and you would get q = 43.6%; the direction, not the number, decides the answer.
Result: dominant allele frequency 10%; 18 of the 19 affected people in 100 are heterozygous
Example 5 — An X-linked allele measured in men
Given: 8% of males show the trait · X-linked recessive
- Males are hemizygous, so the male rate is q itself: 8%.
- Females need it twice: 0.64% affected (1 in 156), with 14.72% carriers (1 in 6.8) and 84.64% carrying neither copy.
- There is no single p² + 2pq + q² table for the whole population at such a locus, which is why this mode prints the two sexes separately.
Result: q = 8%; female carriers 14.72%, affected females 0.64%
Example 6 — From carrier frequency to a stranger’s risk
Given: 2% of the population carries one copy · random mating
- Two people chosen at random are both carriers 2% × 2% = 0.04% of the time.
- When they are, one pregnancy in four is affected, so the population figure is 0.04% × ¼ = 0.01% — one affected birth in 10,000.
- Start from q = 1% instead and the chain gives carriers 1.98% and one affected birth in 10,203, which is the same arithmetic run from the other end.
Result: 0.04% of random couples are both carriers; 1 affected birth in 10,000
Example 7 — Three alleles, six classes
Given: 100 people typed at a codominant locus · AA 14, AB 18, AC 14, BB 20, BC 18, CC 16
- Allele frequencies from the counts: A 30%, B 38%, C 32%.
- Six classes minus three frequencies leave 3 degrees of freedom — df = classes − alleles, not classes − 1.
- χ² = 12.22 at df 3 gives p = 0.67%, and observed heterozygosity 50% against an expected 66.32% puts F at 0.246: a clear heterozygote deficit.
- No exact test is available at three alleles, so this is a chi-square result and the page says so.
Result: df = 3; χ² 12.22, p = 0.67%; F = 0.246
Want the reasoning behind the numbers? Read How to Use the Hardy-Weinberg Equation.
How to interpret the result
The primary card changes what it means with the mode. In counts mode it is a p-value: the chance that a sample this size, drawn from a population actually at equilibrium, would sit this far from the expected classes. A small p-value is evidence an assumption failed, not a diagnosis of which one — inbreeding, the Wahlund effect of typing two subpopulations as one, and null alleles at a PCR site all remove heterozygotes and produce the same number. A large p-value is weaker still: it means this sample cannot see the deviation, which is exactly what Example 2 shows at 15 people.
F is the more informative half of the readout, because it carries a sign. Positive means heterozygotes are missing relative to expectation; negative means they are over-represented, which happens under heterozygote advantage or when the wrong genotypes were scored. It is a scaled quantity, so it can be compared across loci in a way a chi-square cannot — χ² grows with sample size, while F describes the deficit itself. At an allele frequency near the extremes F becomes unstable, since He heads toward zero and the ratio stops meaning anything.
The interval matters more than people expect. A sample of 100 gives you 200 alleles, and a q̂ of 25% carries a 95% range of 19.5–31.4% — wide enough that the carrier figure derived from it spans 31.4–43.1%. Population screening numbers quoted as "1 in 50 carriers" are point estimates of exactly this kind, and when two studies disagree by a few percentage points the intervals, not the points, decide whether anyone has found anything. See the Genetics collection for the other ways to read the same allele.
Two risks on this page look alike and are not interchangeable. The carrier frequency 2pq is a statement about a population; the one-in-four risk for the child of two known carriers is a Mendelian fact about a family, and combining them is how the random-couple chain gets misread as advice for a specific couple. If the parents are already known to be carriers, use the Punnett square calculator and its family-risk mode; if you only know how common the disease is, this page is the right direction of travel, and how to read a Punnett square covers the boundary between the two.
Assumptions
- Random mating with respect to this locus, no assortative preference and no consanguinity beyond what F is meant to summarize.
- A large population, so sampling drift is the only reason the classes would differ from p² : 2pq : q².
- No selection, mutation or migration at the locus during the generation being counted.
- Genotypes scored correctly and completely — every class visible, which is not true of a dominant-phenotype assay.
- Frequencies are stable enough within the sampled group that one p̂ describes it; a mixed sample is an average of two equations, not one.
Limitations
- Autosomal, one locus at a time, with two or three alleles counted and two to four frequencies entered; polygenic, mitochondrial and imprinted inheritance are outside the model.
- The exact test is biallelic. Three-allele loci are judged on the chi-square alone, and its approximation is only as good as the expected counts.
- No multiple-locus correction: run twenty markers at p < 0.05 and one failure is the expected outcome, not a discovery.
- X-linked mode gives population expectations by sex, not a family’s risks; skewed X-inactivation and X-linked dominant conditions behave differently.
- Penetrance is assumed complete wherever a phenotype rate is inverted into an allele frequency, and a genotype-phenotype mismatch will move q by more than the sampling interval does.
Common mistakes
- Typing percentages or ratios into the count fields — the test needs a sample size to know how much a deviation weighs.
- Using df = classes − 1 for the goodness-of-fit test instead of classes − alleles, which understates the p-value at two alleles and badly understates it at three.
- Reading a non-significant chi-square as proof the population is at equilibrium, when it can only mean the sample was too small to tell.
- Applying q = √(affected) to a dominant trait, which silently solves the wrong equation.
- Quoting 2pq as "the chance their child is affected" — it is the share of strangers carrying one copy, and the family figure comes from the parents.
- Expecting one genotype table from an X-linked locus, then wondering why the female rate is nothing like the male rate.
- Averaging heterozygote deficit across loci without reporting He, so a locus with almost no variation looks like a locus with inbreeding.
FAQ
How do you calculate allele frequency from a population sample?
Why is the heterozygote frequency 2pq and not pq?
What degrees of freedom does the Hardy-Weinberg chi-square use?
When should I not trust the chi-square result?
What is the difference between p < 0.05 and F?
How do you get carrier frequency from disease incidence?
Does Hardy-Weinberg work for X-linked genes?
What if my trait is dominant?
Is this the same as a Punnett square?
Scientific Sources
- Wikipedia — Hardy–Weinberg principle (the (p + q)² derivation, the chi-square test with its degrees-of-freedom rule, F = 1 − Ho/He, the conditional exact distribution, and the X-linked expectation) · Tier 3 source
- Wikipedia — Binomial proportion confidence interval (the Wilson score interval used for the allele frequency) · Tier 3 source
- Wikipedia — Fisher's exact test (why a chi-square needs large expected cell counts, and the usual 5 and 10 thresholds) · Tier 3 source
- Wikipedia — Pearson's chi-squared test (df = categories − parameters, and the right-tail p-value) · Tier 3 source
External links open in a new tab and carry rel="nofollow". We cite primary references (NIST, NIH/NCBI, peer-reviewed papers) and established manufacturer technical documentation (NEB, Thermo Fisher, Promega, IDT). Calculated results are estimates; your protocol and manufacturer guidance take precedence.
Last reviewed: 2026-10 · Method version: 1.0