All who die in God's grace and friendship, but still imperfectly purified, are indeed assured of their eternal salvation; but after death they undergo purification, so as to achieve the holiness necessary to enter the joy of heaven.  The Church gives the name Purgatory to this final purification of the elect, which is entirely different from the punishment of the damned.  This teaching is also based on the practice of prayer for the dead, already mentioned in Sacred Scripture: "Therefore [Judas Maccabeus] made atonement for the dead, that they might be delivered from their sin." From the beginning the Church has honored the memory of the dead and offered prayers in suffrage for them, above all the Eucharistic sacrifice, so that, thus purified, they may attain the beatific vision of God. The Church also commends almsgiving, indulgences, and works of penance undertaken on behalf of the dead:
Let us help and commemorate them. If Job's sons were purified by their father's sacrifice, why would we doubt that our offerings for the dead bring them some consolation? Let us not hesitate to help those who have died and to offer our prayers for them.
 To understand this doctrine and practice of the Church, it is necessary to understand that sin has a double consequence. Grave sin deprives us of communion with God and therefore makes us incapable of eternal life, the privation of which is called the "eternal punishment" of sin. On the other hand every sin, even venial, entails an unhealthy attachment to creatures, which must be purified either here on earth, or after death in the state called Purgatory. This purification frees one from what is called the "temporal punishment" of sin. These two punishments must not be conceived of as a kind of vengeance inflicted by God from without, but as following from the very nature of sin. A conversion which proceeds from a fervent charity can attain the complete purification of the sinner in such a way that no punishment would remain.
Prayer for the souls in purgatory
Saint Gertrude the Great was a 13th century German mystic and Benedictine nun who showed "tender sympathy towards the souls in purgatory". In one mystical vision Our Lord dictated the following prayer and promised to release a thousand souls from purgatory each time it was said. The prayer was extended to include living sinners as well.
Eternal Father, I offer Thee the most Precious Blood of Thy Divine Son, Jesus Christ, in union with the Masses said throughout the world today, for all the Holy Souls in Purgatory, for sinners everywhere, for sinners in the Universal Church, for those in my own home and within my family. Amen.