Most nightmares have their basis in our waking lives. They can stem from something we have seen or from what had been preoccupying our thoughts during the day. They can be the consequence of stressful or frightening experiences.
Nightmares are most common among small children. Their frequency generally decreases with age up to the time of puberty. Among adults, nightmares are more common among women than among men.
Someone who has a nightmare should not become worried. A major cause of nightmares is eating late at night right before going to sleep. When a person sleeps right after eating, his accelerated metabolic processes affect his body and mental activity during sleep.
Apart from that, it is recommended for a Muslim to sleep in a state of ritual purity. This mean it is best to perform wudû’ before going to bed.
It is also recommended to lie on the right side when going to sleep. The Prophet (peace be upon him) used to sleep on his right side and instructed his followers to do so.
He said [Sahîh al-Bukhârî (247) and Sahîh Muslim (2710)]:
If you come to your sleeping place, perform your ablutions as you would for prayer, then lay down on your right side, then say:
“O Allah, I have submitted myself to You and have entrusted to You my affairs, and I have taken refuge in You, in both hope and fear of You. There is no refuge or sanctuary from You except with You. O Allah! I believe in Your Book that You have revealed and Your Prophet whom You have sent.”
If you die in on this night of yours, then you will be on the natural faith. Make these words the last thing that you utter.
It is also strongly recommended to recite the other remembrances prescribed for sleeping that we find in the Sunnah.
Among the most important of these is to recite Ayah al-Kursî, which is verse 255 of Sûrah al-Baqarah. Abu Hurayrah relates [Sahîh al-Bukharî (3275)]:
The Messenger of Allah (peace be upon him) put me in charge of guarding the Zakâh of Ramadan. Someone came and began to take handfuls of food. I grabbed him and said:
“By Allah, I will take you to the Messenger of Allah!”
He said: “I am poor and have a large family and I am in dire need.”
So I let him go and in the morning the Prophet said: “O Abû Hurayrah! What did you do with your prisoner yesterday?”
I said: “O Messenger of Allah, he complained of dire need and a large family, so I showed mercy to him and let him go on his way.”
He said: “He lied to you and he will come back.” So, from the words of the Messenger of Allah, I knew that he would come back. Therefore, I lay in wait for him and he came and once more began to take handfuls of food.
I seized him and said: “I will take you to Allah’s Messenger!”
He said: “Let me go. I am poor and have a large family. I will not come back again.” So I had mercy upon him and let him go his way.
In the morning the Messenger of Allah (peace be upon him) said to me: “O Abû Hurayrah! What did you do with your prisoner yesterday?”
I said: “O Messenger of Allah, he complained of dire need and a large family, so I showed mercy to him and let him go on his way.”
He said: “He lied to you and he will come back.” So I lay in wait for him a third time and he came and began to take handfuls of food. I grabbed him and said: “I will take you to Allah’s Messenger! This is the third time. You claimed you would not come back and then you came back.”
He said: “Let me go. I will teach you some words which will help you with Allah.”
I said: “What are they?”
He said: “When you go to bed, recite Ayah al-Kursî, “Allah, there is no god but He, the Living, the Self-Sustaining…” to the end of the verse. You will have someone guarding over you from Allah and the devils will not come near you until the morning.”
So I let him go on his way. In the morning, the Messenger of Allah (peace be upon him) said to me: “What did you do with your prisoner yesterday?”
I said: “O Messenger of Allah! He claimed that he would teach me some words which would help me with Allah, so I let him go on his way.”
He said: “What are they?”
I said: “He said to me, ‘When you go to bed, recite Ayah al-Kursî to the end.’ He said to me: ‘You will have someone guarding over you from Allah and the devils will not come near you until the morning’.”
The Prophet (peace be upon him) said: “He told you the truth even though he is a liar. Do you know whom you were speaking with on these three days, Abû Hurayrah?”
I said: “No.”
The Prophet said: “It was Satan.”
It is also recommended to recite the last two chapters of the Qur’ân – Sûrah al-Falaq and Sûrah al-Nâs. They are known as “the two chapters of seeking Allah’s refuge.”
One important supplication by which we seek refuge with Allah from the evil of human beings and jinn is: “In the name of Allah, with whose name nothing brings harm in the heavens or on Earth.”
The Prophet (peace be upon him) informed us that whoever recites this three times every morning and evening, that he will not come to harm. [Sunan Abî Dâwûd (4425) Sunan al-Tirmidhî (3310) and Sunan Ibn Mâjah