When she completes her days of purity for a son or a daughter, she shall bring a sheep… (Leviticus 12:6)
So, a woman has a baby. If it’s a boy, she has 7 impure days, followed by 33 pure days, for a total of 40. If it’s a girl, she has 14 impure days, followed by 66 pure days, for a total of 80. In either case, when she’s done with her pure days, she’s to bring a sacrifice at the Temple. In addition to the year-old sheep, which was brought as a burnt offering (korban olah), she is to bring a pigeon or a dove as a sin offering (korban chatas).
This sacrifice is one of the variable kinds. Optimally, the woman should bring a sheep for her olah offering. If this is too expensive for her means, she may substitute two pigeons or two doves.
If a woman jumped the gun and brought her sacrifice during her pure days, it doesn’t work. She could bring it any time after the 41st day (for a boy) or the 81st day (for a girl), but she would not be permitted to eat from sacrifices until she did so.
The reason for the olah is to give thanks to God for helping her to endure through the travails of childbirth – delivering her from delivery, as it were. But why does she have to bring a sin offering? The Talmud in Niddah (31b) tells us that the chatas is to atone for the knee-jerk reaction one naturally has to the pain of childbirth, which is to swear off marital relations so as never to go through that painful experience again. Once the memory of the pain subsides, she changes her mind. (I have a video of my wife in the recovery room following the birth of my son. She’s saying, “We’ll have to spoil him because he’s going to be an only child!” His younger siblings would disagree with that forecast – it’s a real-life example of the wisdom of Chazal!)
This mitzvah only applied to women, and only in Temple times. The details of this mitzvah are discussed in the Talmud in tractate Niddah (31b) and tractate Kerisos (7b-8a). It is codified in the Mishneh Torah in the first chapter of Hilchos Mechusarei Kaparah and it is #76 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos.