Shake out the bed first, then say it
You do not know what settled there after you left it.
سُبْحَانَكَ اللَّهُمَّ رَبِّي بِكَ وَضَعْتُ جَنْبِي وَبِكَ أَرْفَعُهُ إِنْ أَمْسَكْتَ نَفْسِي فَاغْفِرْ لَهَا وَإِنْ أَرْسَلْتَهَا فَاحْفَظْهَا بِمَا تَحْفَظُ بِهِ عِبَادَكَ الصَّالِحِينَ
Subḥānaka-Llāhumma rabbī, bika waḍaʿtu janbī wa bika arfaʿuh. In amsakta nafsī fa-ghfir lahā, wa in arsaltahā fa-ḥfaẓhā bimā taḥfaẓu bihi ʿibādaka-ṣ-ṣāliḥīn
“Glory to You, O Allah my Lord. By You I have laid down my side and by You I raise it. If You keep my soul, forgive it. And if You send it back, guard it with what You use to guard Your righteous servants.”
Where this comes from
Shake the bed out with the inside of your waist wrapper first, and say the name of Allah, because you do not know what took your place while you were gone. Then lie on the right side and say this. It splits the night into two outcomes and asks for something in each.
The full narration
Abu Huraira reported Allah's Messenger (ﷺ) as say- ing:When any one of you goes to bed, he should take hold of the hem of his lower garment and then should clean (his bed) with the help of that and then should recite the name of Allah for he himself does tiot know what he left behind him on his bed, and when he intends to lie on bed, he should lie on his right side and utter these words:" Hallowed be Allah, my Lord. It is with Thine (grace) that I place my side (upon the bed) and it is with Thee that I take it up (after sleep), and in case Thou withholdst my being (if thou causest me to die), then grant pardon to my being, and if Thou keepst (this process of breathing on), then protect it with that with which Thou protected Thine pious servants
Source
Ṣaḥīḥ Muslim · 6892
- Agreed upon as authentic (al-Bukhārī / Muslim)