According to WebMD, the gender of a baby can typically be determined via ultrasound at 20 weeks into a pregnancy. An ultrasound exam is usually administered to all pregnant women at around 20 weeks.
WebMD stresses that an ultrasound exam does not always result in an accurate determination of the baby's gender. Ultrasound results are necessarily subject to interpretation by a medical professional. Since the test results must be interpreted, there is always the possibility of human error.
Patients should tell their doctor in advance of the exam if they do not want to know the gender of their baby.