According to 1 Peter 3:21:
“Baptism . . . now saves you, not as a removal of dirt from the body, but as an appeal to God for a clear conscience, through the Resurrection of Jesus Christ.”
In keeping with this language, the Nicene Creed states:
“I confess one baptism for the forgiveness of sins.”
And the Catechism of the Catholic Church affirms:
“The Lord himself affirms that baptism is necessary for salvation [Jn 3:5]. . . . Baptism is necessary for salvation for those to whom the Gospel has been proclaimed and who have had the possibility of asking for this sacrament [Mk 16:16]” (CCC 1257).
The necessity of baptism for salvation is broadly recognized among Christians, including non-Catholic ones. For example, Martin Luther wrote:
“Baptism is no human plaything but is instituted by God himself. Moreover, it is solemnly and strictly commanded that we must be baptized or we shall not be saved. We are not to regard it as an indifferent matter, then, like putting on a new red coat. It is of the greatest importance that we regard baptism as excellent, glorious, and exalted” (Large Catechism 4:6).
But God has not made baptism necessary in an absolute sense, so that anyone who fails to receive it is lost. Down through history Christians have recognized that there are exceptions, and that it is possible to be saved through “baptism of blood” (martyrdom for Christ) or “baptism of desire” (a desire for baptism that has not yet been received).
Even those who do not understand the importance of baptism can be said to have an unconscious desire for it if they would be willing to do what God wants them to do for their salvation. Thus the Catechism of the Catholic Church states:
“Those who die for the faith, those who are catechumens, and all those who, without knowing of the Church but acting under the inspiration of grace, seek God sincerely and strive to fulfill his will, are saved even if they have not been baptized” (CCC 1281; the salvation of unbaptized infants is also possible; see CCC 1260–61, 1283).
Both the necessity of baptism and the exceptional cases have been recognized all the way down through Church history.
For example, it’s easy to show from passages from the Church Fathers illustrate that Christians in the first ages recognized the ordinary necessity of water baptism as well as the legitimacy of baptism by desire or blood.
Or get my book, The Fathers Know Best!