Hardy-Weinberg Equilibrium Calculator

Free Hardy-Weinberg calculator for genetics students. Calculate genotype frequencies from allele frequencies, or work backward from observed genotype counts with a built in chi square equilibrium test.

100% Free
Privacy Protected
Instant Results
Hardy-Weinberg Equilibrium Calculator

Enter the frequency of the dominant allele (p). The recessive allele frequency (q) is calculated automatically since p + q = 1.

How to Use This Hardy-Weinberg Calculator

This tool works in two directions, and you can use either one depending on what your assignment gives you. If you already know the frequency of the dominant allele, use the first tab. Enter p as a decimal between 0 and 1, and the calculator works out q, along with the expected genotype frequencies and, if you provide a population size, the expected head count for each genotype.

If instead you have real or sample data, such as the number of individuals with each genotype from a survey or a lab exercise, use the second tab. Enter the observed counts for AA, Aa, and aa, and the calculator backs out the allele frequencies, compares your observed counts against what Hardy-Weinberg would predict, and runs a chi square test so you can say with some statistical backing whether the population looks like it is in equilibrium.

What the Hardy-Weinberg Principle Actually Says

The Hardy-Weinberg principle is often introduced as a formula to memorize, but it is really a null hypothesis for population genetics. It describes what allele and genotype frequencies would look like generation after generation if nothing were pushing the population to change.

That is the useful part. Real populations are shaped by mutation, migration, genetic drift, natural selection, and non random mating, all of which are forms of evolution in progress. By calculating what the population would look like without any of that happening, and then comparing it to what you actually observe, you get a concrete way to detect that evolution is occurring, and sometimes even estimate how strong its effect is.

Breaking Down the Equation

There are two equations working together here. The first, p + q = 1, simply says that in a gene with two alleles, the frequency of the dominant allele and the frequency of the recessive allele have to add up to the whole population's worth of alleles at that locus. If 70 percent of the alleles are dominant, the remaining 30 percent must be recessive.

The second equation, p squared plus 2pq plus q squared equals 1, expands that into genotypes. p squared is the chance of inheriting two dominant alleles, one from each parent. q squared is the chance of inheriting two recessive alleles. And 2pq covers the heterozygous case, since there are two ways to end up with one of each: a dominant allele from the mother and a recessive one from the father, or the other way around.

Working through an example makes this concrete. If p equals 0.7, then q equals 0.3. Squaring and combining those gives 49 percent AA, 42 percent Aa, and 9 percent aa, which is exactly what the forward calculation above will show you if you try those numbers.

The Five Conditions Behind the Model

Hardy-Weinberg equilibrium only holds when five conditions are met at the same time: no mutation, no migration into or out of the population, no genetic drift, which in practice means the population is effectively infinite, no natural selection acting on the trait, and completely random mating with respect to the trait in question.

No real population satisfies all five perfectly, and that is expected rather than a flaw in the model. The value of Hardy-Weinberg is not that it predicts reality exactly. It is that any measurable gap between the prediction and the real data points to one or more of those five forces at work, which is often the actual point of the assignment or the research question.

A Brief History of the Hardy-Weinberg Principle

The principle carries two names because it was discovered independently and almost simultaneously by two people working in completely different fields. Godfrey Harold Hardy was a British mathematician with little interest in biology, and Wilhelm Weinberg was a German physician who spent his career studying human genetics and multiple births. Neither man knew of the other's work when they each published the same core result in 1908.

Hardy's motivation was almost accidental. He had been asked at a cricket match by a geneticist colleague, Reginald Punnett of Punnett square fame, to help settle a debate about why a dominant trait does not simply take over a population generation after generation, which some biologists at the time genuinely believed should happen. Hardy worked out the algebra in what he considered a trivial exercise and published it almost as an aside. Weinberg arrived at the identical mathematical result independently while studying inheritance patterns in twins, and published it in the same year in a separate German language journal.

For decades, English language textbooks credited only Hardy, since Weinberg's paper was written in German and took longer to reach a wider international audience. Today both names are used together, which is a fairer reflection of how the discovery actually happened, and a useful reminder that the same mathematical insight can emerge from very different starting points when the underlying logic is sound.

A Complete Worked Example

The compact example above shows the arithmetic. Walking through a full genetics scenario the way it might appear on an assignment makes the reasoning behind it easier to hold onto.

Suppose a wildlife biologist is studying a population of 1,000 field mice and wants to know whether a coat color gene is behaving as Hardy-Weinberg would predict. A dominant allele B produces brown fur, and a recessive allele b produces gray fur when present in two copies. The biologist catches and examines all 1,000 mice and counts 640 with brown fur and 360 with gray fur.

Since gray fur only appears in the bb genotype, the 360 gray mice represent q squared directly. Dividing 360 by 1,000 gives a q squared of 0.36, and taking the square root gives q equals 0.6. Since p and q must sum to 1, p equals 0.4. From there, the expected genotype counts under Hardy-Weinberg are p squared times 1,000 for BB, which is 160, 2pq times 1,000 for Bb, which is 480, and q squared times 1,000 for bb, which is 360, the same number counted directly.

Notice that the 640 brown mice observed in the field combine both the BB and Bb genotypes, since both produce a brown appearance. The expected brown total under Hardy-Weinberg is 160 plus 480, which equals 640, exactly matching what was observed. Because the observed and expected numbers line up this closely, a chi square test on this data would return a value near zero, and the population would be judged to be in Hardy-Weinberg equilibrium for this gene. This is precisely the kind of phenotype based problem that shows up often on exams, where you are given visible trait counts rather than genotype counts directly and have to work backward through the recessive phenotype first.

It is worth noticing what this example does not tell you. The biologist cannot look at any single brown mouse and know whether it is BB or Bb just from its coat color, since both genotypes look identical from the outside. The 160 and 480 figures are population level expectations calculated from the allele frequencies, not a claim about any individual animal, which is a distinction that trips students up when a question asks about the genotype of one specific organism rather than the population as a whole.

Common Mistakes Students Make With Hardy-Weinberg Problems

The single most common error is confusing allele frequency with genotype frequency. A student who is told that 36 percent of a population shows a recessive trait will sometimes set p or q directly equal to 0.36, when in fact that 36 percent figure is q squared, the frequency of the recessive genotype, not the recessive allele itself. The correct first step is almost always to take a square root before doing anything else.

A second frequent mistake is applying Hardy-Weinberg math to a trait that does not follow simple dominant and recessive inheritance. The two allele equations only work cleanly for genes with straightforward dominance. Traits involving codominance, incomplete dominance, or multiple alleles, such as ABO blood type, require an adjusted version of the same logic rather than the standard p squared plus 2pq plus q squared formula used here.

A third mistake shows up specifically in chi square problems, where students calculate the chi square value correctly but then misread the conclusion, treating a chi square value below the critical value as proof that the population is definitely in equilibrium, rather than as an indication that the data does not provide strong enough evidence to say otherwise. Failing to reject a hypothesis is not the same as proving it true, and exam questions sometimes specifically test whether a student understands that distinction.

Frequently Asked Questions

1. What is the Hardy-Weinberg equilibrium?

The Hardy-Weinberg principle states that allele and genotype frequencies in a population remain constant across generations in the absence of evolutionary influences such as mutation, migration, genetic drift, natural selection, and non-random mating. It provides a mathematical baseline for detecting when evolution is occurring.

2. What do p and q mean in the Hardy-Weinberg equation?

p is the frequency of the dominant allele and q is the frequency of the recessive allele in a population. Because there are only two alleles at the locus, p and q always sum to 1, and the genotype frequencies follow p² + 2pq + q² = 1.

3. How do you test if a population is in Hardy-Weinberg equilibrium?

Compare the observed genotype counts in a sample to the counts expected under Hardy-Weinberg proportions, then run a chi-square goodness-of-fit test. If the chi-square value exceeds the critical value for the appropriate degrees of freedom, the population is considered to deviate significantly from equilibrium.

4. What are the assumptions behind Hardy-Weinberg equilibrium?

Five conditions must hold: no mutation, no migration (gene flow), no genetic drift (an infinitely large population), no natural selection, and random mating. Real populations rarely meet all five perfectly, which is exactly why deviations from Hardy-Weinberg predictions are used to detect evolution in action.

5. Why is the critical value 3.841 in this calculator?

With one degree of freedom (three genotype categories minus one, minus one parameter estimated from the data), the chi-square critical value at the standard significance level of 0.05 is 3.841. A calculated chi-square below this value means the observed deviation from expected counts is not statistically significant.

6. Can this be extended to genes with more than two alleles?

Yes, in principle. Multi-allele systems extend the same logic, with genotype frequency terms for every possible allele pairing. This calculator covers the standard two-allele case taught in most introductory genetics courses, which is also the form used in the large majority of homework and exam problems.

Reading the Chi-Square Test

The chi square test in the reverse calculation compares your observed genotype counts to the counts Hardy-Weinberg would predict given the same total population and the allele frequencies calculated from your data. The bigger the gap between observed and expected, the larger the chi square value.

For this two allele, three genotype setup, the relevant degrees of freedom is 1, because you start with 3 categories and lose one degree of freedom for the total and one for estimating an allele frequency from the data itself. At the standard significance level of 0.05, the critical value for 1 degree of freedom is 3.841. If your calculated chi square comes in below that, the deviation from Hardy-Weinberg expectations is small enough that it could plausibly be due to chance, so the population is treated as being in equilibrium. If it comes in above 3.841, the deviation is considered statistically significant, which means something other than chance is probably driving it.

Where This Shows Up Outside the Classroom

Hardy-Weinberg calculations are not just a textbook exercise. Public health researchers use the same logic to estimate how common a disease causing allele is in a population from the number of people who show the recessive phenotype, which matters for genetic counseling and screening programs.

Conservation biologists use it to check whether a small, isolated population, such as an endangered species with a shrinking habitat, is showing signs of genetic drift or inbreeding, both of which would show up as a departure from Hardy-Weinberg expectations. Forensic and population geneticists rely on the same equations when interpreting DNA evidence, since allele frequency tables for things like short tandem repeats are built on this exact math.

If genetics coursework in general, not just this one topic, is where your semester is getting stuck, our biology class support covers everything from Punnett squares through population genetics and exam preparation.

Extending Hardy-Weinberg Beyond Two Alleles

The two allele version covered by this calculator is what appears in the overwhelming majority of introductory genetics coursework, but the underlying logic extends to genes with more than two alleles, and it is worth understanding conceptually even if the arithmetic gets more involved.

The classic teaching example is human ABO blood type, which is controlled by three alleles at a single gene: IA, IB, and i. With three alleles, the equation expands from p squared plus 2pq plus q squared equals 1 to a version with three frequency terms, conventionally written as p plus q plus r equals 1, where p, q, and r represent the frequencies of IA, IB, and i respectively. Squaring that expanded sum produces six genotype terms instead of three, since there are now six possible combinations of the three alleles taken two at a time, including the case of inheriting the same allele twice.

What keeps this manageable is that the same core assumptions apply regardless of how many alleles are involved: no mutation, no migration, no drift, no selection, and random mating. The main practical difference is that solving for individual allele frequencies from observed phenotype counts requires a bit more algebra, since blood type genetics also involves dominance relationships between IA, IB, and i that affect which genotypes produce which visible blood type. Most courses introduce this extension only after students are comfortable with the two allele case this calculator handles, which is why it is treated here as a conceptual bridge rather than a second calculator mode.

When a Population Is Not in Equilibrium

A chi square result that exceeds the critical value is not a dead end. It is usually the more interesting outcome, since it means something measurable is happening to the population, and figuring out which of the five Hardy-Weinberg conditions is being violated is often the actual assignment or research question behind the calculation.

Natural selection is the most commonly tested explanation in coursework. If one genotype has a survival or reproductive advantage, its frequency will climb across generations faster than Hardy-Weinberg would predict, and the recessive or disadvantaged genotype will be underrepresented relative to expectations. A classic textbook example is a population where the heterozygote has an advantage over both homozygotes, which keeps a recessive allele in circulation at a higher frequency than pure chance would allow, a pattern geneticists call heterozygote advantage.

Small population size is another common culprit, particularly in conservation biology problems. In a small population, random chance alone can shift allele frequencies substantially from one generation to the next simply because fewer individuals means each one contributes a larger share of the next generation's gene pool. This effect, called genetic drift, tends to produce departures from Hardy-Weinberg that look statistically significant even without any selection pressure at all, which is exactly why endangered species with shrinking populations are watched closely for exactly this kind of deviation.

Non random mating is a third possibility worth ruling out before jumping to selection or drift as an explanation. If individuals preferentially mate with others who share their own genotype, a pattern called assortative mating, the population will show more homozygotes and fewer heterozygotes than Hardy-Weinberg predicts, even though the overall allele frequencies have not changed at all. This is a useful distinction on exams, since a chi square deviation caused by non random mating can look superficially similar to one caused by selection, but the underlying biology and the expected pattern across generations are quite different.

Migration and Gene Flow as a Fourth Cause

Migration, sometimes called gene flow when discussed in a genetics context, is the remaining major cause of departure from Hardy-Weinberg equilibrium, and it is easy to overlook because it does not require anything happening within the population itself. If individuals carrying a particular allele move into a population from elsewhere, or if individuals carrying certain alleles are more likely to leave, the allele frequencies shift regardless of survival, reproduction, or mate choice inside the population being studied.

This matters in real conservation and wildlife genetics work because a population that looks like it is drifting or evolving under selection might actually be receiving a steady trickle of new alleles from a neighboring population through occasional interbreeding. Distinguishing gene flow from genetic drift or selection usually requires comparing allele frequencies across multiple, geographically separated populations of the same species rather than looking at a single population's data in isolation, since gene flow tends to make neighboring populations more genetically similar to each other over time, while drift and selection can push them apart.

Taken together, the four causes covered here, selection, drift, non random mating, and gene flow, along with mutation as the fifth and generally slowest acting force, are the complete list of explanations an introductory genetics course expects you to consider whenever a chi square test flags a population as significantly out of Hardy-Weinberg equilibrium. Working through which one best fits the scenario described in a problem, rather than defaulting to natural selection every time, is usually what separates a strong exam answer from a partial one.