God blessed them and said, “Be fruitful and multiply; fill the Earth and master it; rule over the fish of the sea, the birds of the sky and all the creatures that move on the land.” (Genesis 1:28)
There is only one mitzvah in the sedra of Bereishis (and only three mitzvos in the entire Book of Genesis, far fewer than in any other of the Five Books of Moses!). Verse 1:28 tells us that God blessed Adam and Chava (Eve), and He commanded them to “be fruitful and multiply.”
The reason for this mitzvah is simple; God created the world so that it should be used. Since He made it for mankind, it necessitates that there BE a mankind! (The Sefer HaChinuch cites a verse from Isaiah, 45:18, that God made the world so that it should be inhabited.)
The mitzvah to have children is obligatory in all times and places, but only upon men (see Yevamos 65b-66a). Of course, a man cannot fulfill this mitzvah without the help of a woman (who, let’s be honest, does most of the work!), but women were not obligated in the matter because pregnancy and delivery involve a significant risk.
Contextually, it’s only a mitzvah with one’s spouse. Even Ha’Ezer 1:1 begins, “A man is obligated to marry a woman in order to be fruitful and multiply…” Yes, it is physically possible to have children outside of marriage, but that’s a little like serving a roast pig at a Passover Seder; the thing one does right is kind of canceled out by the thing one does wrong.
The obligation is to have a son and a daughter, each of whom is capable of reproducing. (Beis Shammai would consider the obligation fulfilled with two sons, but this position does not reflect the final ruling.)
This mitzvah can be found in the Talmudic tractate of Yevamos, starting on page 61b, and in the Shulchan Aruch in Even Ha’Ezer 1. It is #212 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos and #43 among the 77 positive mitzvos that can be fulfilled today as listed in the Chofetz Chaim’s Sefer HaMitzvos HaKatzar.