During an HSG, a contrast dye is injected into the uterine cavity through the cervix. As the dye moves through the uterus and fallopian tubes, X-ray images are taken. This helps in identifying blockages or abnormalities. The procedure typically takes about 30 minutes and is performed on an outpatient basis.