Your baby's sex is set at conception. At around 7 weeks, your baby's internal sex organs – such as ovaries and testes – begin to form in the abdomen. Male and female sex organs and genitalia look the same at this stage because they're derived from the same structures. At around 9 weeks, boys and girls begin to develop differently.
In girls, a tiny bud emerges between the tissue of the legs. This bud will become the clitoris. The membrane that forms a groove below the bud separates to become the labia minora and the vaginal opening. By 22 weeks, the ovaries are completely formed and move from the abdomen to the pelvis. They already contain a lifetime supply of 6 million eggs.
In boys, the bud develops into the penis and starts to elongate at around 12 weeks. The outer membrane grows into the scrotal sac that will later house the testicles. By 22 weeks, the testes have formed in the abdomen. They already contain immature sperm. Soon they'll begin their descent to the scrotum, but it's a long journey. They'll reach their destination late in pregnancy, or for some boys, after birth.
If you're eager to find out whether you're having a girl or a boy, you'll have to wait until you're at least 17 weeks pregnant. That's when the genitals have developed enough to be seen on an ultrasound.