The Council of Trent infallibly declared that Penance is one of the Seven Sacraments, instituted by Christ.
As with all the Sacraments, its primary purpose and effect is the bestowal of God's Grace, Sanctifying Grace and Sacramental Grace. It's secondary purpose is the forgiveness and absolution of sins.
We receive Sanctifying Grace at our Baptism. It is the presence of Sanctifying Grace in the soul which we refer to when we say we are in a "State of Grace". We must have Sanctifying Grace to be saved, that is we must be in a State of Grace when we die to go to Heaven (directly or via Purgatory). Mortal sin eradicates Sanctifying Grace from the soul. Since we cannot be baptised again, Christ gave us the Sacrament of Penance to restore Sanctyifying Grace to the soul. The only exception to this is perfect contrition at the moment of death when the Sacrament is not available. Those who are not baptised will not go to Heaven, and those baptised who have committed mortal sin after their baptism without confessing it in the Sacrament of Penance will not go to Heaven.
But also in the Sacrament of Penance, we receive a special Sacramental Grace that assists us (if we call on it) to abide by our resolution not to sin again. It assists us to overcome temptations that particularly trouble us and to grow in grace.
Our Lord instituted the Sacrament on the day of His Resurrection when He entered the Supper Room and gave the Apostles the power to remit sin by saying: "Receive ye the Holy Ghost; whose sins you shall forgive they are forgiven; and whose sins you shall retain they are retained."
The parts of the Sacrament are the penitent's contrition, confession and satisfaction and the priest's absolution.
Contrition is sorrow for our sins, such that we detest them and resolve never to commit them again. It is also referred to as detachment from sin. It is a word that means the crushing or breaking up into pieces, such as when a stone is pulverised. It has come to mean sorrow for sins because it is the pulverisation of the hard heart of a sinner sorry for having offended God.
Confession requires us to admit our sins to the priest.
Satisfaction or Penance is prayer or other good works that the priest requires of the penitent in satisfaction for his sins, the "price" for the priceless gift of absolution.
Absolution is the moment when God's forgiveness is imparted through the Church, when the Sacrament is conferred. It consists of the priest saying "ego te absolvo" ("I absolve you from your sin").
A valid confession requires on the part of the penitent, that he or she be sorry for having offended God, resolve not to sin again, to confess all mortal sins remembered in kind and number and perform the penance imposed. On the part of the priest, the words "I absolve you" must be used, the priest must be validly ordained and (unlike all other Sacraments) must have been granted the faculty by his Bishop to hear confessions. A priest who does not have this faculty (eg, a laicized priest or a priest of the Society of St Pius X) cannot validly absolve anyone except in danger of death where a priest with the faculty is not available.
This, of all the Sacraments, is the most personal and intimate. Baptism, although it is conferred on an individual, is a community event. It is the initiation of the individual into the Body of Christ, the Church. The Eucharist, although it is an intimate union between Christ Himself and the communicant, is also a sign of the communion and unity of the whole Church. Marriage is a Sacrament for the couple in the presence of their families and the whole Church. But, Penance is a Sacrament that we attend alone, particularly when we are in a state of mortal sin, when we are alone directly with our loving Father. We are like the Prodigal Son who returns to his father and is received joyfully, a huge banquet being thrown in our honour. But, we do not have the jealous elder brother who has not strayed resenting our return, we have only Christ who consoles us and brings us the joy of forgiveness.