We already discussed, in Mitzvah #18, the way in which certain firstborn animals are consecrated. This is because God spared the Jews and their livestock when He killed all the firstborns of Egypt. A donkey is unique in that it is the only non-kosher animal with a firstborn status, although because it is not kosher, it is also not itself consecrated. Rather, the owner of the donkey must exchange it for a sheep, which he would then give to a kohein. (We non-farmer types, who didn’t have flocks, could use the value of a sheep rather than an actual sheep.) The time to redeem the donkey is within thirty days of its birth. After it's redeemed, the donkey belongs to its original owner (an Israelite), the sheep belongs to the kohein, and neither one is sanctified in any way.
The obvious question is why the donkey should be singled out from all non-kosher animals for redemption of its firstborn. R. Chanina asked this question in tractate Bechoros (5b). R. Eliezer answered him that it is a decree of the Torah, so we may not always understand the reasons, but he offered one suggestion: the Jews used donkeys to transport the wealth they earned when they left Egypt. The redemption of donkeys may be in commemoration of this, with an aspect of symbolic gratitude.
This mitzvah can be found in the Talmud in the first chapter of tractate Bechoros. In the Shulchan Aruch, it can be found in Yoreh Deah 321. This mitzvah is #81 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos and #55 of the 77 positive mitzvos that can be fulfilled today as listed in the Chofetz Chaim’s Sefer HaMitzvos HaKatzar. This mitzvah applies to both men and women, in all times and places, but only to Yisraelim (Israelites); it does not apply to kohanim and Leviim (priests and Levites).