The first several weeks or so in the womb a baby is neither male nor female with organs that are able to turn into either set of genitalia. Then, after those several weeks it looks for the Sry gene, generally found in the Y chromosome, and if it finds it, it immediately tells the body to start to develop into a male. If it does not find it after a couple more weeks, it turns it into a female. However, there are irregularities all the time. Sometimes that Sry gene is found in an X chromosome, and you are left with a XX male, who looks in most regards male but has many numerous feminine physical traits like widened hips, etc. Vice versa there are also XY females, and even XXY people and XXXY, etc. The more chromosomes generally leads to mental retardation though, so there aren't many of those. There's also the issue of sex (male or female in the physical sense) versus gender (male or female in the mental sense), and that's a whole nother story.
tl;dr graduate high school. This shit is Biology 10fucking1 for fuck's sake.