When a sperm and egg join to form a zygote, whether that sperm carried an X chromosome or a Y chromosome determines the eventual sex of the developing fetus. However, for the first seven weeks of development a male and female fetus are indistinguishable.
Shortly after the seventh week, the presence of a gene called “Sry” on the Y chromosome directs the development of the testes. These new testes then begin to produce testosterone (a hormone associated with male development) and another hormone called Müllerian inhibiting hormone; together, these two hormones cause the disintegration of the female internal organs and further the development of male internal and external anatomy. In the absence of the Sry gene and the Müllerian inhibiting hormones, the female external and internal anatomy will form.