Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
muslim:648cAbū Bakr b. Abū Shaybah > ʿAbdullāh b. Idrīs > Shuʿbah > Abū ʿImrān > ʿAbdullāh b. al-Ṣāmit > Abū Dhar > In Khalīlī Awṣānī

My friend (the Holy Prophet) bade me to hear and obey (the ruler) even if he is a slave having his feet and arms cut off, and observe prayer at its prescribed time. (And further said): It you find people having observed the prayer, you in fact saved your prayer, otherwise (if you join with them) that would be a Nafl prayer for you.  

مسلم:٦٤٨cوَحَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ حَدَّثَنَا عَبْدُ اللَّهِ بْنُ إِدْرِيسَ عَنْ شُعْبَةَ عَنْ أَبِي عِمْرَانَ عَنْ عَبْدِ اللَّهِ بْنِ الصَّامِتِ عَنْ أَبِي ذَرٍّ قَالَ إِنَّ خَلِيلِي أَوْصَانِي

أَنْ أَسْمَعَ وَأُطِيعَ وَإِنْ كَانَ عَبْدًا مُجَدَّعَ الأَطْرَافِ وَأَنْ أُصَلِّيَ الصَّلاَةَ لِوَقْتِهَا فَإِنْ أَدْرَكْتَ الْقَوْمَ وَقَدْ صَلَّوْا كُنْتَ قَدْ أَحْرَزْتَ صَلاَتَكَ وَإِلاَّ كَانَتْ لَكَ نَافِلَةً  


See similar narrations below:

Collected by Ibn Ḥibbān

ذِكْرُ الْبَيَانِ بِأَنَّ قَوْلَهُ ﷺ وَإِلَّا فَهِيَ نَافِلَةٌ أَرَادَ بِهِ الصَّلَاةَ الثَّانِيَةَ لَا الْأُولَى

ibnhibban:1719ʿAbdullāh b. Muḥammad al-Azdī > Isḥāq b. Ibrāhīm > Marḥūm b. ʿAbd al-ʿAzīz al-Qurashī > Abū ʿImrān al-Jawnī > ʿAbdullāh b. al-Ṣāmit > Abū Dhar

[Machine] "For me, O Messenger of Allah ﷺ , pray the prayer on time. If you come to a group and they have already prayed, then you have safeguarded your prayer. But if they have not prayed, then you should pray with them, and it will be a voluntary prayer for you."  

ابن حبّان:١٧١٩أَخْبَرَنَا عَبْدُ اللَّهِ بْنُ مُحَمَّدٍ الْأَزْدِيُّ قَالَ حَدَّثَنَا إِسْحَاقُ بْنُ إِبْرَاهِيمَ قَالَ أَخْبَرَنَا مَرْحُومُ بْنُ عَبْدِ الْعَزِيزِ الْقُرَشِيُّ قَالَ حَدَّثَنَا أَبُو عِمْرَانَ الْجَوْنِيُّ عَنْ عَبْدِ اللَّهِ بْنِ الصَّامِتِ عَنْ أَبِي ذَرٍّ قَالَ قَالَ

لِي رَسُولُ اللَّهِ ﷺ «صَلِّ الصَّلَاةَ لِوَقْتِهَا فَإِنْ أَتَيْتَ الْقَوْمَ وَقَدْ صَلَّوْا كُنْتَ قَدْ أَحْرَزْتَ صَلَاتَكَ وَإِنْ لَمْ يَكُونُوا صَلَّوْا صَلَّيْتَ مَعَهُمْ وَكَانَتْ لَكَ نَافِلَةً»