The mitzvot of redeeming the firstborn appears in the Torah in several places. The first time is in
שמות פרק יג, יג: "וכל בכור אדם בבניך תפדה"
The mitzvah appears explicitly again in
במדבר פרק יח, טו: "אך פדה תפדה את בכור האדם"
The command for the mitzvah was given to Moses when the Israelites left Egypt. Following the plague of firstborns, which affected only the firstborn Egyptians, Moses was ordered to consecrate the firstborn of the Israelites, so that they would serve in the Temple. After Israel sinned with the sin of the calf, the right to work in the tabernacle was taken away from the firstborn and given to the Levites. The transfer of firstfruits from the authority of the "consecration" therefore required a special redemption, through five shekels of silver, given to the priests. Redemption must be made with coins or objects worth five shekels of silver, a total of about 96 grams of pure silver.