The Messenger of Allah ﷺ said, "When one of you goes to his bed, let him take the inner part of his lower garment and dust off his bed with it, mentioning the name of Allah, for he does not know what may have come onto his bed in his absence. Then when he wishes to lie down, let him lie on his right side and say, 'Glory be to You, Allah my Lord. By Your name I lay my side down, and by Your name I raise it up. If You take my soul, forgive it, and if You release it, protect it with that by which You protect Your righteous servants.'"
أن رسول الله ﷺ قال: إذا آوى أحدكم إلى فراشه، فليأخذ داخلة إزاره، فلينفض بها فراشه، وليسم الله، فإنه لا يعلم ما خلفه بعده على فراشه، فإذا أراد أن يضطجع، فليضطجع على شقه الأيمن، وليقل: سبحانك اللهم ربي بك وضعت جنبي، وبك أرفعه، إن أمسكت نفسي فاغفر لها، وإن أرسلتها فاحفظها بما تحفظ به عبادك الصالحين.
Bukhari related it in the Book of Supplications (6320), and Muslim in the Book of Remembrance and Supplication (2714), both through the route of Ubaydullah bin Umar, who said, Saeed bin Abu Saeed Maqburi told me, from his father, from Abu Hurairah, and he mentioned it. The wording given is that of Muslim.