Before entering one says: "Allahumma inni a'udhu bika min al-khubuthi wa'l-khaba'ith" (O Allah, I seek refuge with You from the male and female devils), as narrated by Anas ibn Malik (Sahih al-Bukhari 142). On leaving, one says "Ghufranaka" (I seek Your forgiveness), narrated from 'A'ishah (Sunan Abi Dawud 30 and Sunan al-Tirmidhi 7, graded sahih). Entering with the left foot and leaving with the right is what the scholars derived from the Prophet's general practice of beginning with the right in acts of honour and the left in their opposite; it is a recommended etiquette rather than something with its own explicit hadith. One should not face the qiblah or turn one's back to it while relieving oneself in open ground, as in the hadith of Abu Ayyub al-Ansari, "When you go to relieve yourselves, do not face the qiblah nor turn your backs to it; face east or west instead" (Sahih al-Bukhari 394, agreed upon) — the majority permit it inside built structures where a barrier stands between the person and the qiblah. One should not hold the private part or perform istinja' with the right hand (Sahih al-Bukhari 154). It is also from the adab to conceal oneself, to avoid needless speech, and to avoid urinating in stagnant water or in the paths and shaded places where people gather.
Q&A · Purification
What are the sunnahs and duas for entering and leaving the toilet?
Evidence — the daleel
Sahih al-Bukhari 142 ṢaḥīḥSunan Abi Dawud 30Sunan al-Tirmidhi 7Sahih al-Bukhari 394 ṢaḥīḥSahih al-Bukhari 154 Ṣaḥīḥ
On deen2u
Informational, not a personal fatwa. Consult a qualified scholar for rulings on your situation.