Skip to content

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

Three alleles is what a codominant marker or an ABO-type locus gives you: every class is visible, and the test gains degrees of freedom.

Count people, not percentages: the test needs the sample size to know how much to trust the deviation.

All six classes of a three-allele locus. Leave this mode alone if your assay only scores dominant versus recessive.

Leave blank for a two-allele locus. The frequencies you do fill in must add up to 100%.

The two directions solve different equations, so they give very different allele frequencies from the same 19%.

Birth incidence or population prevalence, as a percentage. 1 in 10 000 is 0.01%.

Red-green colour blindness in Western European men is about 8%, which is why the female rate is far lower.

Screening programmes publish this number: for cystic fibrosis in European-ancestry populations it is commonly quoted near 1 in 25.

Hardy-Weinberg test p-value4.55 %
Allele A frequency75 %
Allele a frequency25 %
Heterozygotes observed30 %
Heterozygotes expected37.5 %
Inbreeding coefficient F0.2
Chi-square statistic4
Degrees of freedom1 degrees
Exact test p-value5.8858 %
Allele frequency, 95% low19.5082 %
Allele frequency, 95% high31.4341 %
Carrier frequency, 95% low31.405 %
Carrier frequency, 95% high43.1061 %
People needed, expected count 580 people
Heterozygous classes combined— %
Homozygous classes combined— %
Affected— %
Carriers— %
Carriers among unaffected— %
Affected males— %
One carrier in— people
One affected in— people
Random couple, both carriers— %
One affected birth in— births

What the population should look like

Each row is one genotype class: how many people were counted in it, and how many the squaring rule expects from the allele frequencies above.

GenotypeObservedExpected frequencyExpected people
AA6056.25%56.25
Aa3037.5%37.5
aa106.25%6.25

How many carriers a disease rate implies

The same engine, run backward from four incidence bands, under complete penetrance and random mating. Nothing in this table is typed in by hand, so it cannot disagree with your own result.

Affected birthsAllele frequency qCarriers 2pqCarriers among unaffectedOne carrier in
1 in 1,0003.1623%6.1246%6.1307%16.3277
1 in 10,0001%1.98%1.9802%50.5051
1 in 25,0000.6325%1.2569%1.257%79.5601
1 in 1,000,0000.1%0.1998%0.1998%500.5005

Read as population figures. A couple already known to be carriers has a one-in-four risk per pregnancy whatever this table says, and that question belongs to the Punnett square page.

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

Allele frequency from counts: p̂ = (2·nAA + nAa) / 2N, q̂ = 1 − p̂
Expected classes (2 alleles): f(AA) = p², f(Aa) = 2pq, f(aa) = q²
Expected classes (k alleles): f(ij) = pᵢpⱼ if i = j, 2pᵢpⱼ if i ≠ j
Chi-square test: χ² = Σ (O − E)² / E, df = classes − alleles (1 for two alleles, 3 for three)
Inbreeding coefficient: F = 1 − Ho/He, He = 1 − Σpᵢ²
Wilson 95% interval: (p̂ + z²/2n ± z√(p̂(1−p̂)/n + z²/4n²)) / (1 + z²/n), n = 2N alleles
From a recessive rate: q = √(affected), carrier = 2pq, carrier among unaffected = 2q/(1 + q)
From a dominant rate: q = √(1 − affected), p = 1 − q
X-linked: male affected = q; female affected = q², carrier = 2pq
Random couple: P(both carriers) = C², P(affected child) = C²/4
p and q are frequencies in a population, not probabilities for one pregnancy. N is people; 2N is the alleles actually observed, which is the denominator every test here uses.

Variables and units

SymbolMeaningUnit
NIndividuals typed in the samplepeople
nAA, nAa, naaPeople counted in each genotype classpeople
p, qFrequencies of the two alleles, p + q = 1%
pᵢFrequency of allele i at a multi-allele locus%
HoObserved heterozygote fraction, nAa / N%
HeExpected heterozygosity, 1 − Σpᵢ²%
FHeterozygote deficit relative to expectation; 0 at equilibrium—
χ²Sum of squared observed-minus-expected gaps, scaled by expectation—
dfGenotype classes minus the allele frequencies estimated from the same data—
CCarrier frequency, 2pq%

How hardy-weinberg is calculated

  1. Count alleles, not people: 2N of them, with each homozygote contributing two and each heterozygote one.
  2. Square the allele frequencies to get the classes the population would show at equilibrium, and multiply by N to get expected headcounts.
  3. Subtract: (O − E)² / E summed over classes is the chi-square statistic, judged against df = classes − alleles.
  4. Report the heterozygote gap as F = 1 − Ho/He, keeping the sign, because the direction names the kind of assumption that failed.
  5. Bound the estimate: Wilson score interval on q̂ over 2N alleles, carried through 2q(1−q) for the carrier frequency.
  6. 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.
  7. 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

  1. Alleles: 200 in total, 150 A (2·60 + 30) and 50 a, so p̂ = 75% and q̂ = 25%.
  2. Expected at equilibrium: 56.25 AA, 37.5 Aa, 6.25 aa — the sample has 7.5 fewer heterozygotes than the squaring rule wants.
  3. χ² = 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.
  4. 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

  1. p̂ = 66.67% and q̂ = 33.33%, so the expected aa count is 1.67 people.
  2. 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.
  3. 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

  1. Affected = q² = 0.01%, so q = √0.0001 = 1%.
  2. Carriers = 2pq = 1.98% of everybody — about one person in 50.5, and every one of them healthy.
  3. 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

  1. The affected are p² + 2pq = 1 − q², so q = √(1 − 0.19) = 0.9 and p = 10%.
  2. 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.
  3. 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

  1. Males are hemizygous, so the male rate is q itself: 8%.
  2. Females need it twice: 0.64% affected (1 in 156), with 14.72% carriers (1 in 6.8) and 84.64% carrying neither copy.
  3. 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

  1. Two people chosen at random are both carriers 2% × 2% = 0.04% of the time.
  2. When they are, one pregnancy in four is affected, so the population figure is 0.04% × ¼ = 0.01% — one affected birth in 10,000.
  3. 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

  1. Allele frequencies from the counts: A 30%, B 38%, C 32%.
  2. Six classes minus three frequencies leave 3 degrees of freedom — df = classes − alleles, not classes − 1.
  3. χ² = 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.
  4. 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?

Count alleles, not people. A homozygote contributes two copies of its allele and a heterozygote one, so p̂ = (2·nAA + nAa) / 2N and q̂ = 1 − p̂. With 60 AA, 30 Aa and 10 aa in 100 people that is 150 A and 50 a out of 200 alleles: p̂ = 75%, q̂ = 25%. Those are the numbers the equilibrium expectation is then built from.

Why is the heterozygote frequency 2pq and not pq?

Because there are two ordered ways to be a heterozygote: the first allele from the mother and the second from the father, or the reverse. (p + q)² = p² + 2pq + q² keeps both, and the factor of two is why a rare recessive allele spends almost all of its time in carriers rather than in affected people.

What degrees of freedom does the Hardy-Weinberg chi-square use?

Classes minus alleles, because the allele frequencies themselves were estimated from the same sample. Two alleles across three classes leaves 1 degree of freedom; three alleles across six classes leaves 3, which is k(k−1)/2 rather than the classes − 1 a plain goodness-of-fit test would use. At df 1 the 5% critical value is 3.84, and this page computes the exact tail instead of comparing against a printed table.

When should I not trust the chi-square result?

When any expected class is small. The usual rule of thumb is an expected count of at least 5, and at one degree of freedom some texts ask for 10 — a stricter figure that is widely described as conservative. This page flags both, prints the exact conditional test beside the chi-square, and names the sample size the locus needs before the rarest expected class reaches 5.

What is the difference between p < 0.05 and F?

The p-value answers "could a population at equilibrium produce a sample this far off?", and it grows with sample size, so a big study can make a trivial deficit significant. F = 1 − Ho/He answers "how big is the deficit?", scaled and signed, which is the number you compare between loci. Report both: a significant chi-square with F = 0.01 is a large sample telling you something small, and F = 0.25 with p = 0.2 is a real-looking deficit the sample cannot yet see.

How do you get carrier frequency from disease incidence?

Take the square root, then double: incidence = q², so q = √incidence, and carriers = 2pq. For 1 in 10,000 births, q = 1% and carriers = 1.98%, about 1 in 50. If you want the figure a counselor quotes to a healthy-family question, use carriers among the unaffected, 2q/(1 + q), which is always the larger number.

Does Hardy-Weinberg work for X-linked genes?

Not as one table. Males carry a single X, so their affected rate equals q, while females need the allele twice (q² affected) or once (2pq carriers). With q = 8% that is 8% of males and 0.64% of females — a twelve-fold difference the standard p² + 2pq + q² table cannot express, which is why this page reports the sexes separately.

What if my trait is dominant?

Then the affected are p² + 2pq = 1 − q², so you take the square root of the unaffected fraction instead: with 19% affected, q = √0.81 = 0.9 and the dominant allele sits at 10%. Almost all affected people are heterozygotes (18 of the 19 per 100), which is the signature of a rare dominant allele and the reason dominant homozygotes are so seldom observed.

Is this the same as a Punnett square?

No, and the two are usually confused. A Punnett square starts from the known genotypes of two parents and predicts their next child; Hardy-Weinberg starts from frequencies in a population and predicts what a sample of strangers looks like. If you know the parents, use the Punnett square calculator. If you know only how common the condition is, use this page.

Scientific Sources

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