The Sixth Commandment commands us: Thou shalt not commit adultery.
After the prohibition of murder, adultery is forbidden. This is fitting, since husband and wife are as one body: "they shall be," says the Lord, "two in one flesh." Therefore, after an injury inflicted upon a man in his own person, none is so grave as that which is inflicted upon a person with whom he is joined. Adultery is forbidden both to the wife and the husband.

Now it must be known that although some believe that adultery is a sin, yet they do not believe that fornication is a mortal sin. Against them stand the words of St. Paul: "For fornicators and adulterers God will judge." (Heb. 13:4) "Do not err: Fornicators nor adulterers, nor the effeminate, nor those who lie shall possess the kingdom of God." (1 Cor. 6:9). Since only mortal sin excludes us from the kingdom of God, fornication must be a mortal sin.
Adultery and fornication are forbidden because they destroy the soul: "He that is an adulterer shall destroy his own soul through the folly of his heart." (Prov. 6:32). It says through the folly of his heart, which means "whenever the flesh dominates the spirit." Secondly, adultery and fornication deprive one of life, for guilty of such should die according to the Law, as we read in Leviticus and Deuteronomy. Sometimes the guilty one is not punished bodily in this life, which is to his disadvantage since punishment of the body may be borne with patience and is conductive to the remission of sins. Nevertheless, he shall be punished in the future life.    (St Thomas Aquinas)

Purity is a virtue that makes us especially dear to God. Jesus Christ says: "Blessed are the clean of heart for they shall see God." (Matt. 5:8.) "O how beautiful," says the Holy Spirit, "is the chaste generation  with glory." (Wisdom 4:1.) Jesus Christ when on earth surrounded Himself with chaste souls for whom He showed special love: His Mother, the Immaculate Virgin Mary; St. Joseph, who is generally represented holding the lily of purity; St. John the Baptist, His Precursor; and St. John the Evangelist, who was the most beloved of His Apostles because he was so pure. The Christian religion is proud of its pure virgin martyrs like St. Agnes, St. Cecilia, St. Catherine and St Agatha, and its models of chaste youth like St. Aloysius and St. John Berchmans (Patron Saint of Altar servers.)

On the other hand, God has shown His abhorrence of the opposite vice, impurity; which is another of the crimes that cry to heaven for vengeance. On two special occasions He punished this sin with most dreadful chastisements. The first occasion was when He sent the Flood to destroy all mankind with the exception of Noe and his family. The second was when He destroyed Sodom and Gomorrah with fire and brimstone. To be pure we must practice mortification and self restraint. Our Lord says: "If any man will come after me let him deny himself." (Matt. 16;24.) We practice that self denial especially by guarding the senses of sight, speech, hearing and touch.

The virtue which controls these four senses of sight, speech, hearing and touch is called modesty. Therefore to be pure we must first be modest. The world laughs at modesty, and so it has become corrupted to the core with the foul vice of impurity, especially through the way women and girls dress and pornography on the Internet.  But as long as modesty guards our sight, and speech, and touch, we shall remain pure.

A necessary precaution to preserve purity is to keep away from things and places and persons that lead to sin. Most powerful helps to preserve purity are:
(a) Prayer to Jesus and His Immaculate Mother.
(b)Frequent use of the Sacraments of Penance and Holy Communion.

Source: Rev. Frean, C.SS.R. Commentary on the Catechism.