In human development, the default sex of an embryo is female
. That is, if development goes unimpeded, the fetus will develop ovaries, fallopian tubes, and other female sexual organs.
Two important genes must fire for a person to develop into a male
The first one which must fire is the SRY gene, which is located on the Y chromosome. This is the gene which tells the undifferentiated gonads to develop into testicles instead of ovaries. If it fires, you're a male, if it doesn't, you're female. The second gene which must comes into play is the MIS gene.
In the early stages of fetal development, both the male and female sexual ducts are in place. Females have semi-developed vas deferens, males have semi-developed fallopian tubes. In the case of the female, the male portions whither away during gestation due to the lack of testosterone. With males, the MIS gene must fire to eliminate the female portions.
When the MIS gene is triggered, probably due to the testosterone created by being a male, the body stops development of the female reproductive organs. Most of the time, both genes activate exactly how they're supposed to, with the SRY gene causes the testicles to develop, and the MIS gene cleans up the internal plumbing. There are occasionally problems which arise, though.
If the SRY gene fails to activate at the right time, either due to genetic damage or environmental factors, the fetus becomes female. They live their life, usually not knowing that, at one point, they were "supposed" to be males. If the MIS gene fails to function, some of the female organs will still develop, causing serious reproductive problems for the man. The man will have fallopian tubes, oviducts, a uterus, and even portions of a vagina; in short, he is a pseudo-hermaphrodite. 90% of the men with such a condition are sterile, as some portion of the female organs blocks the sperm from reaching the penis. The man is able to have near-normal sexual activity, but the semen carries little to no sperm, and thus, can't impregnate the woman.