The Messenger of Allah ﷺ said, "Whoever fasts Ramadan out of faith and seeking reward will have his past sins forgiven, and whoever stands in prayer on Laylat al-Qadr out of faith and seeking reward will have his past sins forgiven."
قال رسول الله ﷺ: من صام رمضان إيمانا واحتسابا غفر له ما تقدم من ذنبه، ومن قام ليلة القدر إيمانا واحتسابا غفر له ما تقدم من ذنبه.
Bukhari related it in the Book of Fasting (1901), and Muslim in the Book of the Prayer of Travelers (760), both from the hadith of Hisham, who said, Yahya bin Abu Kathir told us, from Abu Salama bin Abdul-Rahman, from Abu Hurairah, and he mentioned it with the addition of Laylat al-Qadr. Yahya bin Saeed and Muhammad bin Amr likewise related it, "Whoever fasts Ramadan..." Ibn Abdul-Barr recorded their hadith in Tamhid (7/103–104).