Wa `alaykum as-Salamu wa Rahmatullahi wa Barakatuh.
In the Name of Allah, Most Gracious, Most Merciful.
All praise and thanks are due to Allah, and peace and blessings be upon His Messenger.
In this fatwa:
1- It is known that there are some Islamic etiquette a Muslim should consider when entering or going out from, and while being in the bathroom.
2- The majority of scholars say that it is makruh (disliked) to, unnecessarily, speak in the bathroom/toilet.
Answering your question, Dr. Wael Shehab, PhD in Islamic Studies from Al-Azhar University and currently the Imam of the Downtown Toronto Masjid in Canada, states:
In fact, there are some ethics that a Muslim is recommended to apply when entering, going out from, or/and while in the toilet.
For example, one is recommended when entering the toilet to say,
“Allahumma inni a`udhu bika min al-khubthi wal-khaba’ith”
“O Allah, I seek refuge with You from male and female devils.”
And, when leaving the toilet, he should say,
“Ghufranak (I seek Your forgiveness).”
Allah Almighty knows best.
Editor’s note: This fatwa is from Ask the Scholar’s archive and was originally published at an earlier date.