The Messenger of Allah ﷺ used to say when he lay down to sleep, "Praise be to Allah who has sufficed me, sheltered me, fed me, and given me drink, who has favored me and shown me grace, who has given me generously and abundantly. Praise be to Allah in every state. Allah, Lord of all things and their Sovereign, God of all things, I seek refuge in You from the Fire."
أن رسول الله ﷺ كان يقول إذا أخذ مضجعه: الحمد لله الذي كفاني وآواني وأطعمني وسقاني والذي من علي فأفضل، والذي أعطاني فأجزل، الحمد لله على كل حال، اللهم رب كل شيء ومليكه، وإله كل شيء، أعوذ بك من النار.
It was narrated by Abu Dawud (5058), Ahmad (5983), and Nasai in Amal al-Yawm wal-Layla (798), and Ibn Hibban graded it sahih (5538), all of them through Abdul-Samad bin Abdul-Warith, who said, my father narrated to me, Husayn narrated to us, from Ibn Burayda, from Ibn Umar, and he related it. Nawawi graded it sahih in Adhkar (no. 268). Its chain is hasan because of Abdul-Samad bin Abdul-Warith, and Ibn Hajar graded it hasan in Nataij Afkar, except that Abu Hatim found fault with it because of what Abu Muamar Minqari narrated, from Abdul-Warith, from Husayn Muallim, from Ibn Burayda, from Ibn Umar, that the Prophet ﷺ, and he related it. Abu Hatim said, "The hadith of Abu Muamar is more likely to be correct." Ilal al-Hadith (2049).As for what was narrated from Abu Saeed, from the Prophet ﷺ, who said, "Whoever says when he goes to his bed, 'I seek the forgiveness of Allah the Mighty, besides whom there is no god, the Living, the Sustainer, and I turn to Him in repentance' three times, Allah will forgive his sins, even if they were like the foam of the sea, even if they numbered as the leaves of the trees, even if they numbered as the grains of sand of Alij, even if they numbered as the days of this world", its chain is daif. It was narrated by Tirmidhi (3397) and Ahmad (11074), both from the hadith of Abu Muawiya, Ubaydullah bin Walid Wassafi narrated to us, from Atiya Awfi, from Abu Saeed, and he related it. Tirmidhi said, "This is a gharib hadith, we do not know it except from this route, from the hadith of Wassafi Ubaydullah bin Walid." In some copies of Tirmidhi it says, "This is a hasan gharib hadith." I say, in its chain are Wassafi and Atiya Awfi, and both of them are daif.As for what was narrated from Ali, from the Messenger of Allah ﷺ, that he used to say when lying down to sleep, "O Allah, I seek refuge in Your noble face and Your perfect words from the evil of that whose forelock You hold. O Allah, You remove debt and sin. O Allah, Your army is never defeated, Your promise is never broken, and against You the fortune of the fortunate avails nothing. Glory and praise be to You", the correct view is that it is mursal. It was narrated by Abu Dawud (5052) and Nasai in Amal al-Yawm wal-Layla (767), both through Ahwas bin Jawwab, Ammar bin Zurayq narrated to us, from Abu Ishaq, from Harith and Abu Maysara, from Ali, and he related it. Abu Ishaq Sabi's memory became confused, and Ammar bin Zurayq heard from him late in his life. Israil contradicted him, narrating it from Abu Ishaq, from Abu Maysara, who said, the Messenger of Allah ﷺ used to say when going to sleep, meaning he related it as mursal. Ibn Abu Shayba recorded it (29929). Israil's narration from his grandfather is of the utmost precision, and for this reason Abu Zura and Abu Hatim Razi both preferred the mursal version. See Ilal (1989). As for Nawawi, he graded it sahih in Adhkar, and Ibn Hajar graded it hasan in Nataij Afkar, based on the apparent soundness of the first chain.