How to Calculate Hardy-Weinberg Equilibrium

Hardy-Weinberg equilibrium rests on two short equations that connect allele frequencies to genotype frequencies in a population. If you know the frequency of each version of a gene, you can predict how many individuals should be homozygous or heterozygous, and if you count genotypes in a real sample, you can work backward to get allele frequencies and then check whether the population matches what the equations predict. The math itself is straightforward, but the real value lies in understanding what it means when your numbers do or don’t line up.

The Two Core Equations

For a gene with two variants (call them A and a), you only need two things: p, the frequency of one allele, and q, the frequency of the other. Because there are only two options, p + q = 1. That’s the first equation. If allele A shows up 70% of the time, p = 0.7 and q = 0.3.

The second equation predicts genotype frequencies from those allele frequencies: p² + 2pq + q² = 1. Each term maps to a genotype. p² is the expected proportion of AA homozygotes, 2pq is the expected proportion of Aa heterozygotes, and q² is the expected proportion of aa homozygotes. The logic is simple: for an individual to be AA, they need to receive the A allele from both parents, and if mating is random with respect to this gene, the probability of getting A from one parent is p and from the other is also p, so the combined probability is p × p.

Walking Through a Calculation

Suppose you sample 500 people and genotype them at a single locus. You observe 245 individuals with genotype AA, 210 with Aa, and 45 with aa. Your first step is figuring out the allele frequencies from these raw counts.

Each person carries two copies of the gene, so your sample contains 1,000 alleles total. The AA individuals contribute 490 copies of A (245 × 2). The Aa individuals contribute 210 copies of A and 210 copies of a. The aa individuals contribute 90 copies of a (45 × 2). Add them up: A appears 700 times, so p = 700/1,000 = 0.70. And a appears 300 times, so q = 300/1,000 = 0.30. Quick sanity check: 0.70 + 0.30 = 1. Good.

Now plug those into the genotype equation to get expected frequencies. p² = 0.49, meaning you’d expect 49% AA individuals, or 245 out of 500. 2pq = 0.42, so 210 out of 500 should be Aa. q² = 0.09, predicting 45 aa individuals. In this example, the observed and expected numbers match perfectly, which means the population sits right at Hardy-Weinberg equilibrium. In practice, the numbers almost never land so cleanly.

Testing Whether the Fit Is Good Enough

When observed and expected genotype counts don’t match exactly, you need a way to ask whether the mismatch is just random noise from sampling or something meaningful. The standard approach is a chi-square goodness-of-fit test, which compares observed counts to expected counts across all genotype categories. For a two-allele system, this test has one degree of freedom because once you know the allele frequencies, all three genotype proportions are determined.

The chi-square statistic is calculated by taking each genotype class, subtracting the expected count from the observed count, squaring that difference, dividing by the expected count, and summing the results across all classes. A large value suggests the observed genotypes deviate from what Hardy-Weinberg predicts more than chance alone would explain. You compare your calculated value to a chi-square distribution table to get a p-value: if it falls below 0.05, the deviation is conventionally considered statistically significant.

The standard chi-square approach works well for common scenarios, but it becomes unreliable when your sample is small or when some genotype classes have very few expected counts. In those situations, exact tests produce more trustworthy results. These methods calculate the precise probability of observing your genotype configuration, given the allele counts, without relying on the large-sample approximations that the chi-square test depends on.1PubMed Central. A note on exact tests of Hardy-Weinberg equilibrium One version uses the likelihood ratio as its test statistic rather than the more traditional probability test, which has some conceptual advantages when dealing with multiple alleles and sparse data.2PubMed Central. Exact tests for Hardy-Weinberg proportions

What the Assumptions Actually Are

Hardy-Weinberg equilibrium is not a description of how populations really behave. It’s a null model, a prediction of what genotype frequencies would look like if nothing interesting were happening genetically. The equilibrium holds under a specific set of idealized conditions: mating is random with respect to the gene in question, the population is infinitely large (so no genetic drift), there’s no migration adding or removing alleles, no mutation changing one allele into another, and no natural selection favoring one genotype over others.

No real population satisfies all these conditions simultaneously, which is exactly the point. The equilibrium gives you a baseline. When observed genotype frequencies deviate from that baseline, it tells you that at least one of those assumptions is being violated, and figuring out which one is the interesting part of the analysis.

What Departures from Equilibrium Actually Mean

When you find a significant deviation from Hardy-Weinberg expectations, the pattern of the deviation gives you clues about the underlying cause. Most deviations show up as either an excess or a deficit of heterozygotes compared to what 2pq predicts.

A deficit of heterozygotes, where you see fewer Aa individuals than expected and more of both homozygous classes, often points to inbreeding or population substructure. Wright’s inbreeding coefficient (F) is the standard way to quantify this: it compares observed heterozygosity to expected heterozygosity and expresses the difference as a proportion.3PubMed Central. Detecting selection-induced departures from Hardy-Weinberg proportions An F of zero means the population matches Hardy-Weinberg expectations. Positive values indicate a heterozygote deficit; negative values indicate an excess.

The Wahlund effect is another well-known cause of heterozygote deficits. If you inadvertently pool samples from two or more subpopulations that have different allele frequencies, the combined sample will show fewer heterozygotes than Hardy-Weinberg predicts, even if each subpopulation individually is in equilibrium. Null alleles, which are variants that fail to amplify during genotyping and make true heterozygotes look like homozygotes, produce the same statistical signature.4Journal of Heredity. Revisiting FIS, FST, Wahlund Effects, and Null Alleles

An excess of heterozygotes, on the other hand, can indicate balancing selection, where carrying two different alleles confers a survival advantage. The classic textbook example is sickle-cell trait: heterozygotes for the sickle-cell allele gain some malaria resistance without the severe anemia that homozygotes experience. Selection against homozygotes keeps heterozygote frequency higher than Hardy-Weinberg equilibrium would predict.

When Lab Errors Create False Departures

Not every deviation from Hardy-Weinberg expectations reflects something biologically meaningful. Genotyping errors can create apparent departures that have nothing to do with the population’s actual mating patterns or evolutionary history. Research has shown that Hardy-Weinberg test results are very sensitive to errors involving rare alleles, where a single individual incorrectly scored as homozygous for a rare allele can push a marker out of equilibrium. In some studies, more than half of these influential cases turned out to be genotyping mistakes linked to low-quality DNA samples.5PubMed. Significant deviations from Hardy-Weinberg equilibrium caused by low levels of microsatellite genotyping errors

The tricky part is that the power to detect deviations from Hardy-Weinberg equilibrium caused by genotyping errors is generally low unless the error rate is high or the sample size is very large. And even when you do detect a deviation, you can’t automatically distinguish a genotyping error from a real biological cause without additional investigation.6PubMed Central. Detection of genotyping errors and pseudo-SNPs via deviations from Hardy-Weinberg equilibrium This is why large genetic studies, including genome-wide association studies, routinely use Hardy-Weinberg testing as a quality-control filter: markers that deviate strongly from equilibrium in control subjects are flagged as potential genotyping failures and often excluded from analysis.7PubMed Central. Quality control procedures for genome-wide association studies.

Estimating Carrier Frequencies for Genetic Diseases

One of the most practically useful applications of the Hardy-Weinberg equation is estimating how many people carry a single copy of a recessive disease allele. If you know the incidence of a recessive disease, meaning the proportion of affected individuals (who must be homozygous for the disease allele), you can set that equal to q² and work backward. Take the square root to get q, then calculate 2pq to estimate the carrier frequency.

For example, researchers used this approach to estimate the carrier frequency of Fanconi anemia in the United States. By starting with the birth incidence of the disease and applying the Hardy-Weinberg equation, they estimated that roughly 1 in 181 people in the U.S. carry a Fanconi anemia mutation.8PubMed Central. How high are carrier frequencies of rare recessive syndromes? Contemporary estimates for Fanconi Anemia in the United States and Israel The same strategy has been used for inherited retinal diseases, where carrier frequencies calculated from allele frequencies using the Hardy-Weinberg equation showed high agreement with frequencies derived from large population databases.9PubMed Central. Carrier frequency analysis of mutations causing autosomal-recessive-inherited retinal diseases in the Israeli population

This kind of back-calculation is surprisingly powerful for genetic counseling. When a couple wants to know the probability that they’re both carriers of a rare recessive condition, the Hardy-Weinberg equation provides the starting estimate. It’s not perfect, since it assumes random mating and a well-mixed population, and carrier frequencies can vary sharply among different ethnic groups. But as a first-pass estimate, it works remarkably well for conditions where the disease frequency is reasonably well documented.

Forensic DNA Matching

Forensic genetics relies on Hardy-Weinberg equilibrium to calculate the probability that a DNA profile found at a crime scene could have come from a random unrelated person. The basic logic is straightforward: if a suspect’s profile matches the crime-scene evidence at a given locus, and that locus has a homozygous genotype AA, the probability of a random person sharing that genotype is p², where p is the frequency of allele A in the relevant population. Across multiple independent loci, these probabilities are multiplied together to get an overall match probability.10ScienceDirect (Elsevier). Allowing for within-subpopulation inbreeding in forensic match probabilities

The assumption of Hardy-Weinberg proportions matters a great deal here. If the population from which the suspect is drawn has some degree of inbreeding or substructure, the simple p² calculation underestimates the true probability of a match, which could overstate the strength of the evidence. Forensic statisticians have developed corrections for this, typically by incorporating a small adjustment based on an assumed level of population substructure. The point, though, is that the Hardy-Weinberg equation is baked into the foundation of forensic match probability calculations, and understanding its assumptions is directly relevant to how DNA evidence is interpreted in court.

Genes with More Than Two Alleles

The simple p² + 2pq + q² equation applies neatly to genes with just two variants, but many genes have three, four, or dozens of alleles. The ABO blood group system, for instance, involves three common alleles. The same logic still applies, but the equation expands. With three alleles at frequencies p, q, and r, you get six possible genotype classes, and the expected frequencies are the terms of the trinomial expansion (p + q + r)².

The principles remain identical: square a single allele’s frequency for the corresponding homozygote, and use the cross terms for heterozygotes. Researchers have used this extended Hardy-Weinberg model with ABO blood groups to calculate allele frequencies across populations.11PubMed Central. Allele Frequency of ABO Blood Group Antigen and the Risk of Esophageal Cancer Testing for equilibrium also gets more complicated with more alleles, because the chi-square test can struggle when some genotype classes have very few expected observations. Specialized equivalence tests have been developed for these multi-allele scenarios.12Stats. New Equivalence Tests for Hardy–Weinberg Equilibrium and Multiple Alleles

X-Linked Markers and Unequal Ploidy

Genes on the X chromosome require a modified approach because males carry only one copy while females carry two. For females, the standard Hardy-Weinberg equation applies normally: expected genotype frequencies are p², 2pq, and q². For males, who are hemizygous, the expected genotype frequencies are simply p and q, the allele frequencies themselves, since there is no second allele to pair with.

There’s a subtlety that matters for real populations: because males receive their X chromosome from their mother, male allele frequencies reflect the female allele frequencies of the previous generation. If allele frequencies differ between sexes for any reason, the population won’t reach Hardy-Weinberg proportions after a single round of random mating. Instead, the allele frequencies oscillate, converging on equilibrium over several generations.13PubMed Central. Testing for Hardy–Weinberg equilibrium at biallelic genetic markers on the X chromosome Testing for equilibrium at X-linked markers therefore requires sex-specific analysis rather than pooling males and females together.

Why Equilibrium Doesn’t Always Arrive in One Generation

For standard diploid organisms with autosomal genes, one generation of random mating is enough to bring genotype frequencies to Hardy-Weinberg proportions, as long as the other assumptions hold. This is one of the model’s most elegant properties and one that surprises many students. If you start with any genotype distribution at all, random mating alone resets the genotypes to p² : 2pq : q² in a single generation, and the allele frequencies stay the same indefinitely.

A common misconception is that dominant alleles will inevitably increase in frequency over time, which is exactly the confusion that prompted Hardy’s original 1908 paper. Hardy showed mathematically that dominance has nothing to do with allele frequency change: a dominant allele at 10% will stay at 10% generation after generation unless something like selection, drift, or migration is actively pushing it.14Frontiers in Genetics. Rethinking (again) Hardy-Weinberg and genetic drift in undergraduate biology Students consistently struggle with this idea, partly because the word “dominant” feels like it should mean “winning.”

The one-generation-to-equilibrium rule breaks down in polyploid organisms, which have more than two copies of each chromosome. Many plants and some animals are tetraploid (four copies) or hexaploid (six copies). In tetraploids, genotype frequencies approach Hardy-Weinberg proportions gradually rather than snapping into place after a single round of mating.15Trends in Genetics. Recursive Test of Hardy-Weinberg Equilibrium in Tetraploids Hexaploids are even slower, needing roughly eight to nine generations of random mating to reach approximate equilibrium.16Horticulture Research. Asymptotic tests for Hardy–Weinberg equilibrium in hexaploids The additional chromosome copies create more complex segregation patterns that take multiple generations to sort out.

Measuring Inbreeding from Marker Data

The Hardy-Weinberg framework gives researchers a way to estimate individual inbreeding levels directly from genetic data, without needing family records. The idea is that inbred individuals carry more homozygous genotypes than Hardy-Weinberg equilibrium predicts, so the excess of homozygosity at markers across the genome can serve as a proxy for the inbreeding coefficient. In practice, though, the relationship between marker-based homozygosity and actual pedigree-based inbreeding is not as tight as you might expect.

A study that compared marker-based estimates to known pedigrees found that simply measuring the excess of homozygosity over Hardy-Weinberg expectations, using either hundreds of microsatellite markers or thousands of single-nucleotide variants, did not correlate closely with inbreeding coefficients calculated from four to five generations of family history.17PubMed. Estimating human inbreeding coefficients: comparison of genealogical and marker heterozygosity approaches Alternative approaches, such as looking at runs of homozygosity across stretches of the genome rather than individual markers, perform better.18PubMed Central. On the estimation of inbreeding depression using different measures of inbreeding from molecular markers Runs of homozygosity capture recent inbreeding events more effectively because they reflect long, unbroken chromosome segments inherited from a common ancestor, whereas single-marker homozygosity can arise for many reasons unrelated to inbreeding.

This distinction matters for conservation biology and livestock breeding, where accurate inbreeding estimates affect management decisions. It also highlights a broader lesson about Hardy-Weinberg calculations: the equations give you a powerful first approximation, but the conclusions you draw from deviations depend on understanding the assumptions embedded in the model and the limitations of the data you’re feeding into it.