O my God, I am heartily sorry for having offended thee, and I detest all my sins because of thy just punishments, but most of all because they offend thee, my God, who art all good and deserving of all my love. I firmly resolve, with the help of thy grace, to sin no more and to avoid the near occasion of sin. Amen.
Source of the text: Traditional Act of Contrition in Catholic catechisms and prayer books.
The Act of Contrition is a short prayer telling God you are sorry for your sins and resolving, with his grace, to sin no more. Catholics say it in confession before absolution, and many pray it each night before sleep.
What the Act of Contrition means
Contrition is the first of the penitent's acts in the sacrament of Penance. The Catechism teaches that repentance must be inspired by motives of faith: if it arises from love of God it is called perfect contrition, and if it rests on other motives it is called imperfect.
The traditional prayer names both motives: sorrow because of God's just punishments, but most of all because sin offends God, who is all good. Catechisms have long taught it so that children and adults could voice their sorrow in true words. Several approved wordings exist; this is a standard traditional form.
Sources: Catechism of the Catholic Church, 1492.
How and when to pray it
In confession, after you have told your sins and the priest has given your penance, he will invite you to express your sorrow. Pray the Act of Contrition then, and he will give absolution.
At night, look back over the day, then pray it slowly. It is a good close to an examination of conscience.
A verse from the Douay-Rheims
Have mercy on me, O God, according to thy great mercy. And according to the multitude of thy tender mercies blot out my iniquity.
Douay-Rheims, Ps 50:3 (Hebrew Psalm 51)
A saint tied to this prayer: All Saints, November 1.