Dear Rabbi,

I am pregnant and curious about the gender of the fetus. Is it okay for me to ask the doctor to do a sonogram to find out?

Answer:

Strictly speaking, one is permitted to perform a test to learn the gender of an unborn fetus; however, many have the custom not to perform any tests for this purpose, or, if a sonogram is performed for other reasons, not to ask the doctor what the gender of the child is.

This custom is based on what our sages say in the Midrash:

Seven things are concealed from people:

  1. The day of death.
  2. The day a person will be consoled [from distress and grief].
  3. The absolute truth in a judgment.
  4. How one will earn a livelihood.
  5. What is in a neighbor's heart.
  6. What [is the gender of the child] a woman is bearing.
  7. When the wicked will fall.

…“What a woman is bearing,” for it says (Ecclesiastes 11:5), “As you do not know what is the way of the wind, just as things enclosed in the full womb; so will you not know G‑d's work, who does everything.”1

Rabbi Shmuel Yaffe Ashkenazi (1525-1595) explains in his commentary on the Midrash that “what a woman is bearing” is kept hidden so that the parents don’t become disappointed if they find out that the child’s gender is not what they had hoped for (or that there are medical or developmental issues). On the other hand, if they find that the child’s gender is what they had hoped for, the knowledge could diminish the excitement and anticipation of the birth, which would detract from the strong spirit needed to carry the woman through the difficult labor process.2

See Are There Jewish Customs for Pregnancy and Birth? from the Pregnancy and Birth minisite.