The Sacrament of Baptism is the basis of the whole Christian life, the gateway to life in the Spirit... and the door which gives access to the other sacraments. Through Baptism we are freed from sin and reborn as sons [and daughters] of God; we become members of Christ, are incorporated into the Church and made sharers in her mission. (CCC1213)
Baptism was prefigured in the Old Testament in beautiful accounts, such as Noah and the Great Flood, and Moses and the Israelites as they crossed the Red Sea. We also know of the practice of ritual washings for purification and the forgiveness of sins. In particular, we learned about John the Baptist, who performed a ritual baptism that symbolized a gesture of repentance (Lk 3:3).
Even though Christ did not need to be baptized, he was baptized by John. He was showing us by example what to do and explained the importance of the sacrament itself when he said, "He who believes and is baptized will be saved; but he who does not believe will be condemned" (Mk 16:16). Hence, Baptism is necessary for salvation.