The Messenger of Allah ﷺ said, "Whoever fasts Ramadan out of faith and seeking reward will have his past sins forgiven."
حدثنا أبو بكر بن أبي شيبة حدثنا محمد بن فضيل عن يحيى بن سعيد عن أبي سلمة
قال رسول الله ﷺ من صام رمضان إيمانا واحتسابا غفر له ما تقدم من ذنبه
Bukhari narrated it in the Book of Faith, chapter on fasting Ramadan out of sincere faith, hadith no. 38, from the hadith of Muhammad bin Fudayl. Muslim narrated it in the Book of the Traveler's Prayer, chapter on the encouragement to perform the night prayers of Ramadan, which is tarawih, hadith no. 760, from the hadith of Yahya bin Abu Kathir, from Abu Salama, from the hadith of Abu Salama, with the same wording.