Skip to content
Calcapedia
Science

Hardy-Weinberg Calculator

Find how common each version of a gene is (p and q) and the expected genotype shares p², 2pq and q², with an optional chi-square test.

Level: Grades 11–12

  • Common Core standard HSS.CP.A.2Understand that two events A and B are independent if the probability of A and B occurring together is the product of their probabilities, and use this characterization to determine if they are independent.
Printable worksheet

Hardy-Weinberg Calculator

Inputs
Start from

Result

Dominant allele frequency (p)

0.5425

From 1000 individuals, p = 0.5425 and q = 0.4575; equilibrium predicts genotype frequencies of 0.2943 AA, 0.4964 Aa and 0.2093 aa.

Recessive allele frequency (q)
0.4575
Expected AA frequency (p²)
0.294329.4306%
Expected Aa frequency (2pq)
0.496449.6388%, the carriers of a recessive allele
Expected aa frequency (q²)
0.209320.9306%
Total individuals
1,000
Chi-square statistic (df = 1)
0.2215
p-value
0.6379
At the 5% significance level
No significant departure from Hardy-Weinberg expectations

See the step-by-step solution ↓

Observed genotype counts compared with Hardy-Weinberg expectations
Observed genotype counts compared with Hardy-Weinberg expectations
GenotypeObservedExpectedObserved frequencyExpected frequency
AA298294.310.2980.2943
Aa489496.390.4890.4964
aa213209.310.2130.2093

Step-by-step solution

  1. Add up the individuals to get N, the sample size

    298+489+213=1,000
  2. Find p, the share of A alleles. Each AA carries two A alleles and each Aa carries one, out of 2N alleles in total

    p=2×298+4892×1,000=0.5425
  3. Do the same for q, the share of a alleles. p and q always add up to 1

    q=2×213+4892×1,000=0.4575
  4. Expected share of AA (two dominant copies): the chance of getting A twice, p × p

    p2=0.54252=0.294306
  5. Expected share of Aa (one copy of each): A then a, or a then A, so 2 × p × q

    2pq=2×0.5425×0.4575=0.496388
  6. Expected share of aa (two recessive copies): the chance of getting a twice, q × q

    q2=0.45752=0.209306
  7. Turn each expected share into a head count by multiplying by N

    AA 294.31, Aa 496.39, aa 209.31
  8. Measure how far the real counts are from the expected ones. For each genotype, square the gap and divide by the expected count, then add

    (298−294.3063)2294.3063+(489−496.3875)2496.3875+(213−209.3063)2209.3063=0.22149
  9. Find the p-value: the chance of a gap this big by luck alone. It uses 1 degree of freedom (3 groups − 1 − 1 for estimating p)

    P(χ² ≥ 0.2215)=0.63790726

Test yourself

20 quick questions built from this calculator's formula: work out results, predict what happens when an input changes, and work backward from an answer. Every answer comes with the working.

What this calculator does

Find out how common each version of a gene is in a population, and what mix of genotypes to expect. Each version of a gene is called an allele, and a genotype is the pair of alleles an individual carries. The Hardy-Weinberg principle describes a population that isn't evolving at one gene. Say mating is random, with no selection, mutation, migration or drift (random change from chance). Then the allele frequencies stay the same from one generation to the next. The genotype frequencies settle at p², 2pq and q². That makes it the standard starting point for asking whether something is changing a population.

This calculator works in two directions. You can start from counts of AA, Aa and aa individuals. It then estimates the allele frequencies and predicts the genotype frequencies that balance (equilibrium) would give. It can also run a chi-square test, a standard check of how well the counts fit. Or you can start from the share of individuals showing a recessive trait (one that only shows with two copies). It then works back to the allele frequencies and the expected share of carriers, who have one copy each.

Where it's used

Why this math matters outside the classroom:

  • Carrier frequency. Genetics students find that if 1 in 10,000 people show a recessive trait, q = 0.01 and about 2% of people are carriers.
  • Conservation. Conservation biologists compare observed and expected genotype counts in small populations to spot inbreeding.
  • Detecting evolution. Biology classes use the equilibrium as a baseline, so a shift in allele frequency between generations signals evolution.
  • Class data. A sample of 36 AA, 48 Aa and 16 aa gives p = (72 + 48) ÷ 200 = 0.6 and q = 0.4.
  • Crop breeding. Plant breeders track how often a desired allele appears in a seed population as they select across generations.

Grade level and standards: Grades 11–12; Common Core State Standards for Mathematics HSS.CP.A.2. © Copyright 2010. National Governors Association Center for Best Practices and Council of Chief State School Officers. All rights reserved.

How to use it

  1. Choose whether you have genotype counts, or only the share of individuals showing the recessive trait.
  2. For counts, enter the number of AA, Aa and aa individuals. Leave the chi-square box ticked to test the fit.
  3. For the recessive route, enter the percentage of the population showing the recessive trait.
  4. Read p and q and the expected genotype frequencies. If you ran the test, you'll also see the chi-square value and the p-value.

What the inputs mean

AA (homozygous dominant) count
Whole numbers of individuals, not percentages. You need to be able to tell all three genotypes apart. That's true for codominant markers (where both alleles show) and DNA tests. It isn't true when Aa individuals look the same as AA ones.
Run a chi-square test against Hardy-Weinberg expectations
Compares the observed counts with N·p², N·2pq and N·q², where N is the number of individuals. It has 1 degree of freedom (the number of values free to vary), because p is estimated from the same data.
Share showing the recessive trait (q²)
The share of individuals showing the recessive trait. It equals q² only if the population is in equilibrium. Use decimals for rare traits: 1 in 10,000 is 0.01%.

Formula and method

p = (2·AA + Aa) ÷ (2N)        q = (2·aa + Aa) ÷ (2N)        p + q = 1
expected frequencies: AA = p²,  Aa = 2pq,  aa = q²
χ² = Σ (observed − expected)² ÷ expected,   df = 1
recessive route: q = √(q²),  p = 1 − q

p is the share of A alleles and q is the share of a alleles. AA, Aa and aa are the counts of each genotype, and N is the total number of individuals. Each individual carries two copies of the gene, so N individuals carry 2N alleles. AA individuals add two A alleles each, and Aa individuals (heterozygotes) add one. That gives the formula for p, and the same logic gives q.

Suppose egg and sperm cells (gametes) combine at random. Then the chance of getting A twice is p × p, and a twice is q × q. The chance of one of each is p × q + q × p = 2pq. Multiplying these frequencies by N gives the expected counts.

χ² is the chi-square value, Σ means "add up over the three genotypes", and df is the degrees of freedom. The chi-square value measures how far the observed counts are from the expected ones. The p-value is the chance of a value at least that large if the population really were in equilibrium. A small p-value (below 0.05 here) suggests a real departure.

Sometimes you can only spot the recessive trait. Then its frequency is taken as q², and the square root (√) gives q. This step assumes the population is already in equilibrium, so it can't be used to test equilibrium.

Worked example

A sample of 1,000 individuals contains 298 AA, 489 Aa and 213 aa. Are they consistent with Hardy-Weinberg equilibrium?

  1. N = 298 + 489 + 213 = 1,000.
  2. p = (2 × 298 + 489) ÷ 2,000 = 0.5425 and q = (2 × 213 + 489) ÷ 2,000 = 0.4575.
  3. Expected frequencies: p² ≈ 0.2943, 2pq ≈ 0.4964 and q² ≈ 0.2093, or about 294.31, 496.39 and 209.31 individuals.
  4. χ² = 3.69375² ÷ 294.30625 + 7.3875² ÷ 496.3875 + 3.69375² ÷ 209.30625 ≈ 0.2215.
  5. With 1 degree of freedom the p-value is about 0.6379.

Result: p = 0.5425 and q = 0.4575. The p-value of about 0.638 is well above 0.05. So there's no significant departure from what Hardy-Weinberg predicts.

Understanding the result

A test that isn't significant doesn't prove the population is in equilibrium. It only means this sample gives no strong evidence against it. Small samples have little power to detect departures.

A significant result says the genotype frequencies don't match random mating, but it doesn't say why. Common causes include inbreeding or a population split into groups (often seen as too few Aa individuals). Others are selection, recent migration, or mistakes in how genotypes were recorded.

In the recessive route, 2pq is the expected share of carriers, who have one copy of the recessive allele. For rare recessive traits this is far larger than q². That's why most copies of a rare recessive allele are carried by people or animals who don't show the trait.

Assumptions and limitations

  • One gene with two alleles, in a diploid organism (one with two copies of each gene).
  • Random mating and no selection, mutation, migration or genetic drift in the generation considered.
  • In counts mode, every genotype can be identified, and the sample is representative of the population.
  • In the recessive route, the population is assumed to be in equilibrium, and the recessive trait is fully recessive.
  • Genes with three or more alleles, and sex-linked genes, need different formulas.
  • The chi-square shortcut is unreliable when any expected count is below about 5. An exact test is better for small samples.
  • The test uses a fixed 5% significance level. Choose your own cutoff if your field uses another.
  • Results describe populations, not the risk for any individual, and are not a substitute for genetic counselling.

Frequently asked questions

Why does the chi-square test have only 1 degree of freedom?

There are three genotype groups. Once the total is fixed, that would leave 2 degrees of freedom. One more is lost because p is estimated from the same counts used in the test, leaving 1.

Can I estimate carrier frequency from how common a recessive condition is?

Yes, using the recessive route, as long as you're willing to assume equilibrium. If 0.04% of a population shows a recessive trait, q = 0.02 and about 3.92% are carriers, roughly 1 in 25.5.

Why are p and q based on alleles rather than individuals?

Because parents pass genes on one allele at a time, in egg and sperm cells. Counting alleles, two per individual, tracks what actually goes into the next generation.

What if my sample has only one allele?

Then p or q is zero, and every individual has the same genotype. In that case the population matches equilibrium automatically, with nothing to test. The calculator shows the frequencies but skips the chi-square test.

How this calculator is checked

Method: Hardy-Weinberg principle: allele counting p = (2·AA + Aa)/2N; expected genotype frequencies p², 2pq, q²; Pearson chi-square goodness of fit with 1 degree of freedom, p-value from the regularized incomplete gamma function. The calculation is covered by automated tests with known reference values and edge cases. Last updated 2026-10-18. Found a problem? Tell us.

Embed this calculator

Put this Hardy-Weinberg Calculator on your own website or blog for free. Paste this code where you want it to appear: