Sa'id ibn al-Musayyab said: An Ansari was breathing his last. He said: I narrate to you a tradition, and I narrate it with the intention of getting a reward from Allah. I heard the Messenger of Allah ﷺ say: If any one of you performs ablution and performs it very well, and goes out for prayer, he does not take his right step but Allah records a good work (or blessing) for him, and he does not take his left step but Allah remits one sin from him. Any one of you may reside near the mosque or far from it; if he comes to the mosque and prays in congregation, he will be forgiven (by Allah). If he comes to the mosque while the people had prayed in part, and the prayer remained in part, and he prays in congregation the part he joined, and completed the part he had missed, he will enjoy similarly (i.e. he will be forgiven). If he comes to the mosque when the people had finished prayer, he will enjoy the same. (Using translation from Abū Dāʾūd 563)
"إذا توضَّأ أحدُكمْ فأحْسَنَ الوُضوءَ، ثم خرجَ إلى الصَّلاةِ لم يرفعْ قدَمه اليُمنى إلا كَتَبَ اللهُ ﷻ له حسنَةً، ولمْ يَضَعْ قَدَمَه اليُسْرى إلَّا حَطَّ اللهُ ﷻ عنه سيِّئةً، فَليَقْرُبْ أحدكمْ أوْ لِيَبْعُدْ، فإنْ أتَى المَسجدَ فصلَّى في جماعةٍ غُفِر له، فإنْ أتَى المسجدَ وقدْ صَلَّوْا بعْضًا وَبِقى بعْضٌ صَلَّى ما أدْرَكَ وأَتَمَّ ما بَقِيَ، كان كذلك، فإنْ أتى المَسْجِدَ وقد صلَّوْا فَأتمَّ الصَّلاةَ كان كذلك".