In a diploid if p represents the frequency of allele A and q represents the allele frequency of a, then frequency of AA individuals in a population is p2 . Similarly of aa is q2 and of Aa is 2pq. Hence p2 + 2pq + q2 = 1. This is a binomial expansion of (p + q)2 .
According to Hardy–Weinberg principle, total genes and their alleles in a population or gene pool remains constant. This is called genetic equilibrium. Sum total of all the allelic frequencies is 1 [p + q = 1/(p + q)2 = 1].