It was narrated that Anas bin Malik said:
“Whenever the Messenger of Allah entered the toilet, he would say: ‘A’udhu Billahi minal-khubthi wa’l-khaba’ith (I seek refuge with Allah from male and female devils).'” (Sunan ibn Majah)
Narrated Zayd ibn Arqam: The Apostle of Allah (peace be upon him) said: These privies are frequented by the jinns and devils. So when anyone amongst you goes there, he should say: “I seek refuge in Allah from male and female devils.”
Anas reported: When the Messenger of Allah (may peace be upon him) entered the privy, and in the hadith transmitted by Hushaim (the words are): When the Messenger of Allah (may peace be upon him) entered the lavatory, he used to say: O Allah, I seek refuge in Thee from wicked and noxious things.
Sahih Muslim 3:729