To some extent, this depends on your individual circumstances. For some women, a NIPT (noninvasive prenatal testing) can be performed as early as week 10. It is usually offered to women with a higher risk of having a baby with chromosomal disorders. The NIPT is a blood test that can detect Down syndrome, but it also looks for fragments of the male sex chromosome in your blood, meaning that this test may reveal your baby’s biological gender. Genetic tests, such as chorionic villus sampling (CVS) or amniocentesis, are performed using similar methods. However, these tests are more invasive and carry a small risk of miscarriage.
The most common and safest option is an ultrasound, usually done between 16 and 20 weeks. Your baby’s penis or vulva actually begins to form as early as week 6, but girls and boys still look very similar up until around weeks 14-15. In some cases, the baby may take a closed position and their genitals are not visible by the ultrasound technician. In this case, a gender may not be given until birth.