It is narrated from Sayyiduna Anas (may Allah be pleased with him) that when the Prophet (peace and blessings of Allah be upon him) intended to enter the toilet, he would recite this supplication: "O Allah! I seek refuge with You from male and female evil jinn."
Hadith Referenceالادب المفرد / كتاب / 692
Hadith Gradingالألبانی:صحيح
Hadith Takhrij«صحيح : أخرجه البخاري ، كتاب الوضوء : 142 و مسلم : 375 و أبوداؤد : 4 و الترمذي : 6 و النسائي : 19 و ابن ماجه : 298»
Explanation & Benefits
Shaykh Maulana Usman Muneeb
Benefits and Issues: ➊ The dwelling place of Satan is filthy locations, and he tries to harm a person at the time of relieving himself. Therefore, a Muslim has been instructed to recite this supplication before entering the toilet so that he remains protected from the jinn and devils. The Prophetic instruction is: ((The barrier between the jinn and the private parts of the children of Adam, when one of them enters the toilet, is that he says: Bismillah)) (Sunan Ibn Majah, Book of Purification, Hadith: 297) “The thing that acts as a veil between the jinn and the private parts of the children of Adam is that when he enters the latrine, he says: Bismillah.” ➋ The supplication should be recited before entering the toilet, as is explicitly mentioned in the hadith: when he intended to enter, he would recite it. And when relieving oneself in an open area, one should recite the supplication before lifting the garment.
Source: Fadlullah al-Ahad: Urdu Commentary on al-Adab al-Mufrad, Page: 692