The Hardy-Weinberg calculator above takes a single-locus, two-allele system and does the two things a genetics course actually asks of it. Give it observed counts of the three genotypes and it recovers the underlying allele frequencies p and q, works out the genotype frequencies the Hardy-Weinberg principle predicts from those frequencies, and runs a chi-square goodness-of-fit test to see whether the sample is consistent with the prediction. Give it a known value of p instead and it simply shows you the expected distribution, which is the version you want when the question is theoretical rather than empirical.
Arb Digital publishes this alongside its wider library of free science and statistics tools because the arithmetic is short but the bookkeeping is fiddly, and almost every mistake students make happens in the bookkeeping rather than the biology. The equations are trivial. Remembering that a heterozygote contributes one copy of each allele, and that the degrees of freedom are one rather than two, is what separates a correct answer from a plausible-looking wrong one.
What This Hardy-Weinberg Calculator Does
The Hardy-Weinberg principle describes a null model. It says that in a population that is very large, mating at random with respect to the locus in question, and free from selection, mutation and migration at that locus, allele frequencies do not change between generations, and genotype frequencies settle after a single generation of random mating into the proportions p², 2pq and q². That is the whole claim. It is not a law about how populations behave; it is a statement of what would happen if nothing interesting were happening, which is precisely what makes it useful as a baseline.
The calculator therefore produces two categories of output. The allele frequencies p and q are descriptive: they are simply counts of alleles divided by total alleles, and they are true of your sample whatever forces are acting on it. The expected genotype frequencies and the chi-square statistic are inferential: they compare your sample against the null model and quantify the gap. Keeping those two categories separate in your head prevents the commonest misreading of the whole subject, which is treating a departure from equilibrium as if it were an error in the data.
Boundary worth stating: this is a population-genetics tool that works on frequencies across a group. If you want to work out the offspring ratios from two specific parents, that is a different question and our Punnett square calculator answers it. If you want the raw goodness-of-fit machinery for some other categorical comparison, the general chi-square calculator is the right page.
How to Use It
- Choose your input mode. Observed genotype counts is the mode for sample data from a real or exam-supplied population. Known allele frequency p is for the textbook style of question that hands you a frequency and asks what proportions follow.
- Enter counts of individuals, not alleles. If sixty individuals are AA, enter 60. The tool converts to allele counts internally by doubling the homozygotes and adding the heterozygotes once.
- Read p and q from the hero and the first grid cell. They always sum to one for a two-allele locus, so a pair that does not is a sign that a count was mistyped.
- Compare observed with expected using the bars and the expected-count line. The size and direction of each gap is more informative than the test statistic on its own.
- Read the chi-square value and the verdict last. Choose the significance level before you look at the result, not after.
The Formula and How It's Calculated
Allele frequencies come straight from counting. With N individuals there are 2N alleles at an autosomal locus, so:
p = (2 × count of AA + count of Aa) ÷ 2N and q = (2 × count of aa + count of Aa) ÷ 2N, with p + q = 1.
The Hardy-Weinberg expectation is then the binomial expansion of (p + q)²:
p² + 2pq + q² = 1, giving expected counts of N p² homozygous dominants, 2N pq heterozygotes and N q² homozygous recessives. The factor of two on the heterozygote term exists because Aa can be assembled two ways: an A egg meeting an a sperm, or the reverse. Forgetting it is the single most common arithmetic slip in the topic.
The test statistic is the standard goodness-of-fit sum, χ² = Σ(observed − expected)² ÷ expected, taken across the three genotype classes. The degrees of freedom are one, not two: there are three classes, you lose one for fixing the total sample size and one more for estimating p from the data itself, leaving 3 − 1 − 1 = 1. The tool converts the statistic to a p-value using the exact one-degree-of-freedom relationship, and compares it against the significance level you selected. The expansion of p² + 2pq + q² as the equilibrium genotype expectation is set out in the review Hardy-Weinberg Equilibrium in the Large Scale Genomic Sequencing Era published in Frontiers in Genetics and hosted by the NIH.
Working Through a Real Example
Take a sample of 100 individuals: 60 AA, 30 Aa, 10 aa. Allele A appears 2 × 60 + 30 = 150 times out of 200 total alleles, so p = 0.75 and q = 0.25. The expectation is 100 × 0.5625 = 56.25 AA, 100 × 0.375 = 37.5 Aa and 100 × 0.0625 = 6.25 aa. The chi-square contributions are 3.75²/56.25 = 0.25, 7.5²/37.5 = 1.50 and 3.75²/6.25 = 2.25, summing to 4.00. Against the one-degree-of-freedom critical value of 3.841 at the 0.05 level, that sample departs significantly from equilibrium.
Look at where the departure lives. There are fewer heterozygotes than expected and more of both homozygous classes — the classic signature of a deficit of heterozygotes, which is what inbreeding, population structure, or a null allele that fails to amplify in genotyping all produce. Notice also how much of the total statistic comes from the smallest class: the aa cell contributes more than half the chi-square from a gap of fewer than four individuals, because dividing by a small expected count magnifies everything. That is why a chi-square test with any expected cell below about five should be treated cautiously rather than mechanically.
The Assumptions Are the Interesting Part
Five conditions underpin the model, and each fails in a characteristic way. Infinite population size fails as genetic drift, which pushes frequencies around at random and does so hardest in small populations. Random mating fails as assortative mating or inbreeding, which changes genotype frequencies without changing allele frequencies at all — a point worth pausing on, because it means p and q can look perfectly stable while the population is clearly not in equilibrium. No selection fails when one genotype survives or reproduces better. No mutation fails slowly, at rates usually too small to see in one generation. No migration fails when gene flow brings alleles in at different frequencies.
A departure from equilibrium therefore does not identify its own cause. It is a signal that at least one assumption has broken, and the shape of the departure narrows the field: heterozygote deficit points toward inbreeding, population structure, or technical failure to detect heterozygotes; heterozygote excess points toward outbreeding, balancing selection, or a recently mixed population. In modern sequencing work, a locus that fails a Hardy-Weinberg test is very often flagged as a quality-control problem with the genotype calls rather than as a biological finding, which is a useful reminder that the test detects deviations of any origin.
Why Recessive Traits Hide in Carriers
The most practically useful thing the equations tell you is the ratio of carriers to affected individuals for a rare recessive allele. If q = 0.01, then affected homozygotes are q² = 0.0001, or one in ten thousand, while carriers are 2pq = 2 × 0.99 × 0.01 = 0.0198, or roughly one in fifty. There are about 198 carriers for every affected individual. Halve the allele frequency and the affected rate falls fourfold while the carrier rate only halves, so the ratio gets more extreme the rarer the allele becomes.
This is why rare recessive variants persist rather than being cleared away: almost every copy is sitting invisibly in a heterozygote where selection cannot see it. It is also why counting visible cases badly understates how common an allele is in a population, and why q is normally estimated from the square root of the observed frequency of the recessive phenotype rather than by counting carriers directly. Working with squares and square roots here is where a general-purpose percentage calculator earns its keep, since the numbers get small quickly.
Where the Two-Allele Version Runs Out
This calculator handles the two-allele case, which is what almost all coursework uses. Real loci often have more. With three alleles the same logic extends to the expansion of (p + q + r)², which produces six genotype classes rather than three, and the degrees of freedom rise accordingly. Sex-linked loci break the model differently: males carry one copy of an X-linked allele, so the male phenotype frequency equals the allele frequency directly while females still follow the squared expectation, which is exactly why X-linked recessive conditions appear far more often in males.
Two more limits are worth knowing. The chi-square approximation degrades when expected counts are small, and exact tests are preferred in that situation — large sequencing datasets routinely use them for precisely this reason. And equilibrium is a per-locus statement: a population can sit comfortably at equilibrium at one locus while departing sharply at another, so a single test says nothing about the genome as a whole. The DNA to mRNA converter is the tool to reach for when the question moves from allele frequencies to what a specific sequence actually codes for.
Arb Digital publishes hundreds of free, no-signup tools across science, statistics, finance and everyday maths. Nothing you type into any of them is stored or sold.
Browse All Free Tools Contact Arb DigitalCommon Mistakes to Avoid
- Dropping the factor of two on the heterozygote term. Expected heterozygotes are 2pq, not pq, because Aa can form in two ways.
- Using two degrees of freedom. Because p is estimated from the same data, a two-allele locus has one degree of freedom, not two.
- Entering allele counts where individual counts belong. Sixty AA individuals carry 120 A alleles; the tool does that doubling for you.
- Reading equilibrium as proof that nothing is happening. Selection at other loci, and even strong assortative mating, can leave a locus looking undisturbed.
- Trusting a chi-square with tiny expected cells. When an expected count drops below about five, the approximation becomes unreliable and an exact test is the honest choice.
Related Free Tools From Arb Digital
For single-cross inheritance rather than population frequencies, use the Punnett square calculator. The chi-square calculator handles goodness-of-fit and independence tests outside genetics, and the probability calculator covers the combination rules that sit underneath both. For sequence-level work there is the DNA to mRNA converter. On the statistics side, the standard deviation calculator and the percentage calculator are the two you will reach for most often when writing up results. Everything else lives in the free online tools hub.
Frequently Asked Questions
It is p² + 2pq + q² = 1, where p and q are the frequencies of two alleles at one locus. The three terms give the expected frequencies of the homozygous dominant, heterozygous and homozygous recessive genotypes after one generation of random mating in an idealised population.
Count alleles rather than individuals. p equals twice the number of AA individuals plus the number of Aa individuals, divided by twice the total sample size. q is the same calculation using aa, or simply 1 minus p for a two-allele locus.
There are three genotype classes, but one degree of freedom is lost to fixing the total sample size and another to estimating p from the data. Three minus two leaves one, which is why the 0.05 critical value used is 3.841.
At least one assumption of the model has failed at that locus. Possible causes include non-random mating, genetic drift in a small population, selection, migration, or a technical genotyping problem. The test detects a departure but cannot identify which cause produced it.
Take the frequency of affected individuals as q squared, take its square root to get q, set p as 1 minus q, and then carriers are 2pq. For a condition affecting one in ten thousand, q is 0.01 and the carrier frequency is close to one in fifty.
Not in this simple form. Males carry a single copy of an X-linked locus, so the male phenotype frequency equals the allele frequency directly, while females follow the usual squared expectation. That asymmetry is why X-linked recessive traits are seen far more often in males.
Yes, and that case matters. Inbreeding and assortative mating redistribute alleles into homozygotes without altering p or q at all, so a population can show stable allele frequencies alongside a clear deficit of heterozygotes.
Dominance is about how a genotype is expressed, not about how common an allele is. As the National Human Genome Research Institute explains for alleles, a single copy of a dominant allele is enough to show the trait, which is why AA and Aa share one phenotype while only aa shows the recessive one. Frequency and dominance are independent of each other.
This calculator is an educational tool for population-genetics coursework and general study. It models an idealised two-allele locus and is not a clinical, diagnostic, or genetic-counselling instrument. Carrier and risk questions about a real individual or family should be taken to a qualified clinical geneticist or genetic counsellor. Broader background on how inherited conditions are passed on is available from MedlinePlus Genetics.