Excommunication is defined as "An ecclesiastical censure by which one is more or less excluded from communion with the faithful. It is also called anathema, especially if it is inflicted with formal solemnities on persons notoriously obstinate to reconciliation. Two basic forms of excommunication are legislated by the Code of Canon Law, namely inflicted penalties (ferendae sententiae) and automatic penalties (latae sententiae). In the first type, a penalty does not bind until after it has been imposed on the guilty party. In the second type, the excommunication is incurred by the very commission of the offense, if the law or precept expressly determines this (Canon 1314). Most excommunications are of the second type" (Modern Catholic Dictionary by Fr. John A. Hardon, S.J.)
Through excommunication, the most serious of all penalties, the excommunicated person is forbidden to "...have any ministerial participation in celebrating the Eucharistic Sacrifice or in any other ceremonies whatsoever of public worship,to celebrate the sacraments and sacramentals and to receive the sacraments, to discharge any ecclesiastical offices, ministries or functions whatsoever, or to place acts of governance (Canon 1331)" Excommunication, aside from those invovled in abortion, applies to priests that reveal the sins of penitents (Canon 1388), people that throw away the consecrated bread or wine or keep them for sacrilegious purposes (Canon 1367), or for a heretic, apostate, or schismatic (Canon 1364).
Similar to excommunications are anathemas. See Overheard in the Sacristy for more information. The following is an excerpt from that aforementioned blog:
While "minor excommunication" could be incurred by associating with an excommunicate, and "major excommunication" could be imposed by any bishop, "anathema" was imposed by the Pope in a specific ceremony described in the Pontificale Romanum. Wearing a purple cope (the liturgical color of penitence) and holding a lighted candle, he, surrounded by twelve priests, also with lighted candles, pronounced the anathema with a formula that concluded with the phrase:
"Wherefore in the name of God the All-powerful, Father, Son, and Holy Ghost, of Blessed Peter, Prince of the Apostles, and of all the saints, in virtue of the power which has been given us of binding and loosing in Heaven and on earth, we deprive (Name) himself and all his accomplices and all his abettors of the Communion of the Body and Blood of Our Lord, we separate him from the society of all Christians, we exclude him from the bosom of our Holy Mother the Church in Heaven and on earth, we declare him excommunicated and anathematized and we judge him condemned to eternal fire with Satan and his angels and all the reprobate, so long as he will not burst the fetters of the demon, do penance and satisfy the Church; we deliver him to Satan to mortify his body, that his soul may be saved on the day of judgment."
The priests responded: "Fiat, fiat, fiat" (Let it be done), and all, including the pontiff, cast their lighted candles on the ground. A notice is sent in writing to the priests and neighboring bishops of the name of the one who has been excommunicated and the cause of his excommunication, in order that they may have no communication with him. Although he is delivered to Satan and his angels, he can still, and is even bound to repent. The Pontifical gives the form for absolving him and reconciling him with the Church.
Video of an Anathema taking place:
Image Source: L'Excommunication de Robert le Pieux (The Excommunication of Robert the Pious), a painting by Jean-Paul Laurens.