The honorable Prophet (peace be upon him) guided Muslims to a set of great manners and qualities to be recited before going to sleep. When a Muslim keeps to these manners, he shall gain many good results, such as: tranquility and calmness during his sleep and safety of evils and harms. Accordingly, he wakes up after having a deep and good sleep, high spiritual energy, goodness, and activity. It was authentically proven in Sahih Al Bukhari and Sahih Muslim from the Hadith of Al Bara' ibn `Azib (may Allah be pleased with him) that he said: The Messenger of Allah (peace be upon him) said to me: "When you want to go to bed, perform ablution as you do for Salah, then lie down on your right side and say: "Allahumma aslamtu Nafsy ilaika, wa wajjahtu wajhiya ilaika, wa fawwadtu Amry ilaika, wa alja'tu zhahry ilaika, raghbatan wa rahbatan ilaika, la malja'a wa la manja minka illa ilaika. Amantu bikitabikal-ladhy anzalta wa bi nabiyyikal-ladhy arsalta'. If you should die then (after reciting this) you will die on the religion of Islam (i.e., as a Muslim); so let these words be the last you say (before going to bed)" While I was memorizing it, I said: "Wa birasulikal-ladhy arsalta (in Your Messenger whom You have sent).' The Prophet (peace be upon him) said: "No, but say: Wa binabiyyi-kalladhy arsalta (in Your Prophet whom You have sent)." [Sahih Al Bukhari (No 6311) and Sahih Muslim (No 2710)].
This great Hadith contains some manners which a Muslim should keep to when going to sleep. The Prophet (peace be upon him) guided the one who wants to go to sleep to, first, perform ablution as he does for Salah in order to be in the best manner which is purity. Moreover, he should be pure to recite Dhikr before going to sleep which is the perfect case for a Muslim to mention Allah (may He be Glorified and Exalted). Then the Prophet (peace be upon him) instructed Muslims to sleep on their right side which is the healthiest condition for a person, then the Prophet (peace be upon him) instructed them to start mentioning Allah (may He be Glorified and Exalted) with this great invocation mentioned above.
It is very important for a Muslim to pay more attention and ponder over the meanings of these supplications and the invocations reported from the Prophet (peace be upon him) because using these supplications is the most perfect in the sight of Allah.
When we ponder over this great invocation reported in the Hadith, we find that it contains great meanings and objectives which a Muslim should recall before going to sleep.
As for the Prophet's saying: "Allahumma aslamtu Nafsy ilaika," it means: O Allah, I am full content that my soul be totally under Your Will to do whatever You want with it and destine whatever You want either by causing it to die or to let it come back. Truly, in Your Hands are the keys of the heavens and the earth and the forelocks of all people subject to Your Destiny and Fate to do whatever You want with them; verily, no one can object Your Judgment and no none can overturn Your Ruling.
As for the Prophet's saying: "wa fawwadtu Amry ilaika," it means: I have made all my affairs to You which reflects the full reliance on Allah (may He be Glorified and Exalted) and the complete trust in Him because a person has no might nor strength save in Allah (He may be Exalted).
As for the Prophet's saying: "wa alja'tu zahry ilaika," it means: I put full trust in You and return all matters to You because I am quite sure that there is no one to rely upon but You, no one can help and support me but You and no one can protect me but You. This is an indication that a person is in dire need to Allah (may He be Glorified and Exalted) in all his affairs: in sleep, wakefulness, movement, calmness, and all his conditions.