The main source for the Catholic teaching on indulgences is from Pope Paul VI's apostolic constitution on indulgences, published in 1967 called the Indulgentiarum Doctrina. READ IT HERE
The other main sources are the Catechism of the Catholic Church Catechism
and the Vatican's compilation document of all indulgences. Enchiridion Indulgentiarum
In his document, the Pope writes, “An indulgence is a remission before God of the temporal punishment due to sins whose guilt has already been forgiven." (Indulgentiarum Doctrina)
Temporal or temporary punishment refers to the residual damage caused by sin. It is distinguished from the eternal punishment, which refers to an unrepentant sinner's final destination in Hell. The point is that even after a sin has been forgiven (and therefore the eternal punishment remitted), there may still be purification or satisfaction required to repair the damage done by the sin. That residual damage corresponds to “temporal punishment.” (See Catechism #1472) An indulgence, therefore, is a remission of the temporal punishment left over from a forgiven sin.
Indulgences are of two kinds: partial and plenary. “An indulgence is partial or plenary according as it removes either part or all of the temporal punishment due to sin.” (Indulgentiarum Doctrina) Pretty simple. A partial indulgence removes part of one's temporal punishment, whereas a plenary indulgence removes all of it.
Pope Paul VI notes that "the faithful Christian who is duly disposed gains [the indulgence] under certain prescribed conditions through the action of the Church which, as the minister of redemption, dispenses and applies with authority the treasury of the satisfactions of Christ and the Saints.” (Indulgentiarum Doctrina)
So, what are those conditions?
So we have the three staple conditions: Confession, Communion, and prayers for the Pope. Next there is the spiritual or interior condition, detachment from sin, and finally the particular work. Usually this work or prayer is connected with some special occasion or prayer. For example, making a pilgrimage to a certain spot, doing lectio divina, or observing the year of St. Joseph in a concrete way. More on these below."To acquire a plenary indulgence it is necessary
(1) to perform the work to which the indulgence is attached and to fulfill three [other] conditions:
(2) sacramental confession,
(3) Eucharistic Communion and
(4) prayer for the intentions of the Supreme Pontiff. It is further required that
(5) all attachment to sin, even to venial sin, be absent.If this disposition is in any way less than complete, or if the prescribed three conditions are not fulfilled, the indulgence will be only partial, except for the provisions contained in n.11 for those who are 'impeded.'"
(Indulgentiarum Doctrina)
n. 10—The condition of praying for the Supreme Pontiff's intentions is fully satisfied by reciting one "Our Father" and one "Hail Mary"; nevertheless the individual faithful are free to recite any other prayer according to their own piety and devotion toward the Supreme Pontiff. (Indulgentiarum Doctrina).
n. 9—A single sacramental confession suffices for gaining several plenary indulgences, but Communion must be received and prayers for the Supreme Pontiff's intentions recited for the gaining of each plenary indulgence. (Indulgentiarum Doctrina)
The interpretation that I have heard most often is that one may complete the three standard conditions within a week on either side of the special indulgence prayer, for a total window of 14 days. I have also seen a reference that the 14 has been extended to 20 days! However, I do not have an authoritative source for either of those bits of info. Working on it!5. It is appropriate, but not necessary, that the sacramental Confession and especially Holy Communion and the prayer for the Pope's intentions take place on the same day that the indulgenced work is performed; but it is sufficient that these sacred rites and prayers be carried out within several days (about 20) before or after the indulgenced act.
An indulgence is obtained through the Church who, by virtue of the power of binding and loosing granted her by Christ Jesus, intervenes in favor of individual Christians and opens for them the treasury of the merits of Christ and the saints to obtain from the Father of mercies the remission of the temporal punishments due for their sins. Thus the Church does not want simply to come to the aid of these Christians, but also to spur them to works of devotion, penance, and charity. (CCC 1478)
The idea is that our purification and sanctification occurs, little by little, through the Church's application of Christ's merits. His grace increases our holiness by removing the damage of past sins. The paying of temporal punishment coincides with freedom from sin, purification of its effects, and growth in holiness.
As always, our growth in holiness is not something that we accomplish on our own apart from God's grace. Rather, our efforts cooperate with his grace. Christ is always operative in any act of salvation and sanctification:
"[T]he 'treasury of the Church' is the infinite value, which can never be exhausted, which Christ's merits have before God. They were offered so that the whole of mankind could be set free from sin and attain communion with the Father. In Christ, the Redeemer himself, the satisfactions and merits of his Redemption exist and find their efficacy." (CCC 1476)