Sanctify to Me every firstborn; the first offspring of every womb among the children of Israel, both man and beast, belongs to Me. (Exodus 13:2)
The owner of a domesticated animal must declare the firstborn offspring kodesh (holy) and deliver it to the kohanim (priests), who would offer the animal’s fats on the altar and eat its meat. This is because God killed every firstborn of Egypt – both man and beast – during the last of the ten plagues. The Torah tells us (Numbers 8:17, et al.), that as a consequence of this, the firstborns of Israel are dedicated to God.
The Torah uses the word beheima, meaning a domesticated animal. This law applies to cattle, sheep and goats, but not to wild animals, such as deer, which are chayos in Hebrew, rather than beheimos. (There is also one non-kosher animal included in this law: the donkey, as we shall see. Obviously a donkey was not offered on the altar or eaten by kohanim, but you’ll have to wait until we get to mitzvah #22 for the details.)
This law applies at all times, but only in the land of Israel. This is because Deuteronomy 14:23 equates this mitzvah with tithes, which are only observed in Israel. Now that there is no Temple, the animal cannot be sacrificed but it is still sanctified. It must not be worked or eaten until it becomes blemished in some way and is no longer fit to be dedicated as a firstborn. Outside of Israel, firstborn animals are consecrated by rabbinic law. (The exact details of the animal’s status are actually subject to a difference of opinion. It is possible that a firstborn outside of Israel actually is sanctified and just not sacrificed, even when the Temple is standing.)
This mitzvah is discussed in the Talmud in tractate Bechoros and in the Shulchan Aruch starting in Yoreh Deah 306. It is #79 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos and #53 of the 77 positive mitzvos that can be fulfilled today in the Chofetz Chaim’s Sefer HaMitzvos HaKatzar. This law applies to both men and women; the Rambam says that Levites are exempt, but the Sefer HaChinuch says that even kohanim must offer their own animals on the altar.