The Messenger of Allah ﷺ said, "Whoever fasts Ramadan out of faith and seeking reward will have his past sins forgiven."
حدثنا محمد بن فضيل حدثنا يحيى يعني ابن سعيد عن أبي سلمة
قال رسول الله ﷺ من صام رمضان إيمانا واحتسابا غفر له ما تقدم من ذنبه
[Its chain of transmission is sahih. Yahya bin Saeed is Ansari. Abu Salama is the son of Abdul-Rahman bin Awf. Bukhari related the hadith, in this abbreviated form, at 86:11, from Ibn Salam, from Muhammad bin Fudayl, with this same chain. Bukhari also related it at 4:98-99 at greater length, mentioning Laylat al-Qadr, by way of Hisham Dastawai, from Yahya bin Abu Kathir, from Abu Salama. The Hafiz pointed out some of its other paths of transmission in Fath al-Bari, among them this path through Yahya bin Saeed. Likewise, Muslim related it at 1:210-211, by way of Hisham Dastawai, from Ibn Kathir. Bukhari also related it at 4:221, at greater length, by way of Zuhri, from Abu Salama. See also Targhib wal-Tarhib by Munziri, 2:63-64, where he quotes Khattabi as saying, his words "imanan wahtisaban" mean with intention and firm resolve, that is, he fasts it out of belief and desire for its reward, with his soul content with it, not disliking it, not finding its fast burdensome, and not thinking its days long, but rather seizing the opportunity of its many days for the greatness of the reward.]