In many species, sex determination is genetic: males and females have different alleles or even different genes that specify their sexual morphology. In animals this is often accompanied by chromosomal differences, generally through combinations of XY, ZW, XO, ZO chromosomes, or haplodiploidy. The sexual differentiation is generally triggered by a main gene (a "sex locus"), with a multitude of other genes following in a domino effect.
In other cases, sex is determined by environmental variables (such as temperature) or social variables (e.g. the size of an organism relative to other members of its population). Environmental sex determination preceded the genetically determined systems of birds and mammals; it is thought that a temperature-dependent amniote was the common ancestor of amniotes with sex chromosomes.