Tools & Calculators
Practice
Tools & Calculators

Hardy-Weinberg Calculator (p, q, p², 2pq, q² with Steps)

Enter any one Hardy-Weinberg value (p, q, p², 2pq or q²) as a decimal, percent or fraction, and this calculator works out all five with the steps. Or enter genotype counts to find the allele frequencies and test whether the population is in equilibrium.

Loading the hardy-weinberg calculator…

How to use the Hardy-Weinberg calculator

  1. Choose One known value if the problem gives you a frequency, or Genotype counts if it gives you how many AA, Aa and aa individuals there are.
  2. For a known value, pick which one it is. A recessive trait’s frequency is q². Type it as 0.16, 16% or 1/400.
  3. Optional: add a population size to see how many individuals of each genotype to expect.
  4. Read p and q at the top, the genotype table below, then the steps.

Worked example: from the recessive phenotype

In a population of 1,000 moths, 40 are white, a recessive trait. The rest are dark. How many moths are heterozygous?

  1. White moths are aa, so q² = 40 ÷ 1,000 = 0.04.
  2. q = √0.04 = 0.2.
  3. p = 1 − q = 0.8.
  4. Heterozygotes: 2pq = 2 × 0.8 × 0.2 = 0.32, so 0.32 × 1,000 = 320 moths.
  5. Check: p² = 0.64, and 0.64 + 0.32 + 0.04 = 1.

Notice that you can’t start from the dark moths. Dark moths are a mix of AA and Aa, so their frequency is p² + 2pq, not a single term. The recessive phenotype is the only one that maps to exactly one genotype, which is why most problems start there.

The Hardy-Weinberg equations

For a gene with two alleles, A and a:

  • p + q = 1, where p is the frequency of the dominant allele A and q the frequency of the recessive allele a.
  • p² + 2pq + q² = 1, where p² is the frequency of AA, 2pq of Aa and q² of aa.

The second equation comes from the first. If you pick two alleles at random from the gene pool, the chance of A then A is p × p, of a then a is q × q, and of one of each is pq + qp = 2pq. It’s a Punnett square for a whole population.

Term What it is Example (q² = 0.16)
p Dominant allele frequency 0.6
q Recessive allele frequency 0.4
p² Homozygous dominant (AA) 0.36
2pq Heterozygous carriers (Aa) 0.48
q² Homozygous recessive (aa) 0.16

When you only know 2pq

Knowing the heterozygote frequency gives a quadratic, 2p(1 − p) = 2pq, which has two answers. If 2pq = 0.48, then p could be 0.6 or 0.4. Nothing in 2pq says which allele is more common, so the calculator shows both. 2pq can never be more than 0.5, which happens when p = q = 0.5.

The five conditions for equilibrium

Allele frequencies stay the same from generation to generation only if all five of these hold:

  1. No mutation adding or changing alleles.
  2. Random mating, with no preference for certain genotypes.
  3. No natural selection: every genotype survives and reproduces equally well.
  4. A very large population, so random chance (genetic drift) doesn’t shift frequencies.
  5. No gene flow: no individuals moving in or out.

Real populations almost never meet all five, and that’s the point. Hardy-Weinberg is a null model. When a population’s genotypes don’t match p², 2pq and q², something on that list is happening, and the population is evolving.

Testing a population with genotype counts

Suppose you counted 50 AA, 20 Aa and 30 aa individuals (N = 100). The allele frequency is p = (2 × 50 + 20) ÷ 200 = 0.6, so q = 0.4. In equilibrium you’d expect 36 AA, 48 Aa and 16 aa.

The observed counts have far too few heterozygotes. A chi-square test makes it formal: χ² = (50 − 36)²/36 + (20 − 48)²/48 + (30 − 16)²/16 = 34.03. With 1 degree of freedom (3 genotypes minus 2 alleles), the critical value at p = 0.05 is 3.84, so this population is not in Hardy-Weinberg equilibrium. A shortage of heterozygotes often points to non-random mating, such as inbreeding.

The chi-square calculator walks through the same test in more detail.

Common mistakes

  • Using the dominant phenotype as p². Dominant-looking individuals include carriers. Start from q².
  • Forgetting the square root. q² = 0.09 means q = 0.3, not 0.09.
  • Mixing allele and genotype frequencies. p and q describe alleles; p², 2pq and q² describe individuals.
  • Percent versus decimal. 9% is 0.09. Typing 9 means 9 out of 1, which is impossible.

Keep practicing

Hardy-Weinberg calculator FAQ

What is the Hardy-Weinberg equation?

p² + 2pq + q² = 1, where p is the frequency of the dominant allele and q the recessive allele. p² is the frequency of AA individuals, 2pq of Aa and q² of aa. The alleles also add up: p + q = 1.

How do you find p and q?

Usually you start from the recessive phenotype, because only aa individuals show it. Its frequency is q², so q = √q² and p = 1 − q.

How do you find the frequency of carriers?

Carriers are heterozygotes, so their frequency is 2pq. If 1 in 400 people has a recessive condition, q = 0.05, p = 0.95 and 2pq = 0.095, or 9.5%.

What are the five Hardy-Weinberg conditions?

No mutation, random mating, no natural selection, a very large population (no genetic drift) and no gene flow. When any of them is broken, allele frequencies can change and the population evolves.