Mechanisms
Some species (including most mammals) have a gene or genes on the Y-chromosome that determine maleness. In the case of humans, a single gene (SRY) on the Y-chromosome acts as a signal to set the developmental pathway towards maleness. Other mammals use several genes on the Y-chromosome for that same purpose. Not all male-specific genes are located on the Y-chromosome.
Other species (including most Drosophila species) use the presence of two X chromosomes to determine femaleness. One X chromosome gives putative maleness. The presence of Y-chromosome genes is required for normal male development.
Humans, as well as some other organisms, can have a chromosomal arrangement that is contrary to their phenotypic sex, that is, XX males or XY females. See, for example, XX male syndrome and androgen insensitivity syndrome.
Birds have a similar system of sex determination (ZW sex-determination system), in which it is the females that are heterogametic (ZW), while males are homogametic (ZZ).
Read more about this topic: XY Sex-determination System