Considering p the frequency of one of the alleles and q the frequency of the other allele of a given gene in a population, in this population individuals produce p gametes with the first allele for each q gamete containing the second allele. Therefore the probabilities of formation of homozygous genotype for the first allele is p2, of homozygous genotype for the second allele is q2 and of the heterozygous genotype is p.q + q.p, i.e., 2p.q.
Since the sum of those probabilities necessarily is 1, the resulting mathematical expression is: p2 + 2p.q + q2 = 1.
In general the number of genotypical forms is not identical to the number of phenotypical forms since there are dominance and other interactions between genes that affect the manifestation of the phenotype.