When we follow his blessed teachings with sincerity and persistence, we will see firsthand the blessed impact of following his sunnah in our lives.
So, what you need to do to observe the etiquette of sleeping and avoid bad dreams is the following:
1) Making wudu before you go to sleep.
Al-Bara’ bin ‘Azib (May Allah be pleased with them) reported the Messenger of Allah (peace be upon him) directed me whenever I go to bed, to perform Wudu as I do for Salat then (before sleeping) recite:
“O Allah! I have submitted myself to You, I have turned myself to You, committed my affairs to You and sought Your refuge for protection out of desire for You and fear of You (expecting Your reward and fearing Your punishment). There is no refuge and no place of safety from You but with You. I believe in the Book You have revealed and in the Prophet (peace be upon him) You have sent.”
Messenger of Allah (peace be upon him) added:
“If anyone recites these words and dies during the night, he will die on the true religion, and if he remains alive till the morning, he will obtain good. And make this supplication your last words (before sleeping).” [Al-Bukhari and Muslim].
2) When you go to your bed, recite Ayatul-Kursi (2:255), when you do that a guardian from Allah will be guarding you and Satan will not come near you until dawn. Make sure you recite this verse to keep bad and evil whispers away from you.
3) Dust off your bed-sheet and recite the following dua:
Abu Hurairah (May Allah be pleased with him) reported the Messenger of Allah (peace be upon him) said:
When any of you goes to bed, he should shake off (or dust off) his bed-sheet because he does not know what might have fallen on it after he had left it. Then he should recite:
Bismika Rabbi wada’tujanbi, wabikaarfa’uhu, in amsaktanafsifarhamha, wa in arsaltahafahfazhabimatahfazubihi ‘ibadakas-salihin
With Your Name, my Lord, I place my side (upon the bed) and with Your Grace I will raise it up. If You withhold my soul (cause me to die), have mercy on it but if You let it go (let me live), guard it against which You guarded Your pious slaves. [Al- Bukhari and Muslim].
4) Sleep on your right hand side as recommended by the Prophet [Al Bukhari and Muslim]
5) Recite the dua and adhkar specified before sleeping; including
Subhan Allah. (Thirty-three times)
Al-hamdulillah. (Thirty-three times)
Allahu Akbar. (Thirty-four times)
So, make sure to perform wudu before sleeping, recite ayatul-kursi and do the adhkar (subhanAllah, Al-hamdulillah, Allahu Akbar), and this will insha’Allah keep all harm away from you until next morning.