First, we would like to stress that having anal sex with one’s wife is unlawful in Islam because Allah (exalted and glorified be He) says: (Your women are a tilth for you (to cultivate) so go to your tilth as ye will) (Al-Baqarah 2:223), and the anus is not a place of cultivation. The Messenger of Allah (peace and blessings be upon him) is reported to have said “Allah is not too shy to tell you the truth: do not have intercourse with your wives in the anus.”
The four schools of Islamic jurisprudence and other Muslim jurists have unanimously agreed that anal sex is haram (unlawful).
Sheikh Ahmad Kutty, a senior lecturer and Islamic scholar at the Islamic Institute of Toronto,Ontario, Canada, states: Anal sex is undoubtedly forbidden in Islam. There are authentic traditions of the Prophet (peace and blessings be upon him) explicitly forbidding it. The Prophet (peace and blessings be upon him) is reported to have said, “Do not enter women through their rear ends.” Therefore, stay clear of this practice, and seek to derive sexual pleasure from your spouse only in ways that are clearly lawful. It should help us to know that there is always sufficiency for us in what Allah has declared as halal (lawful).
So I urge you to pray to Allah as follows: “Allahumma aghnini bi halalika `an haramika wa bi ta`atika `an ma`siyatika wa bi fadhlika `amman siwaka” (O Allah, grant me sufficiency in what You have made halal for me so that I do not need to turn to what You have made haram; and make me self-sufficient with Your obedience so that I am not compelled to disobey You; and make me self-sufficient with Your favor so that I don’t need to turn to favor of others).
Now coming to what one must do in order to expiate for these sins, the answer is that it is enough for you to make sincere repentance. In other words, feel deep sorrow and remorse for your action; refrain from such practices immediately and be forever determined not to do it again; finally do some good works. If you can afford to giving some charity to the poor that is undoubtedly a most meritorious act. Allah says: (Good deeds wipe out bad deeds) (Hud 11: 114).
May Allah help us all to love faith and good deeds and abhor sins of all kinds, both inward and outward, and may He shower us all with His mercy and forgiveness. Ameen.