كتاب التفسير
65  
Prophetic Commentary on the Qur'an (Tafseer of the Prophet (pbuh))
(9)
The Statement of Allah: “...The second of two, when they (Muhammad ﷺ and Abü Bakr were in the cave, and he ﷺ said to his companion (Abu Bakr ) ‘Be not sad (or afraid), surely Allah is with us.'" (V.9:40)
(9)
Sahih al-Bukhari 4663

Narrated Abu Bakr:

I was in the company of the Prophet (ﷺ) in the cave, and on seeing the traces of the pagans, I said, "O Allah's Messenger (ﷺ) If one of them (pagans) should lift up his foot, he will see us." He said, "What do you think of two, the third of whom is Allah?"

حَدَّثَنَا عَبْدُ اللَّهِ بْنُ مُحَمَّدٍ، حَدَّثَنَا حَبَّانُ، حَدَّثَنَا هَمَّامٌ، حَدَّثَنَا ثَابِتٌ، حَدَّثَنَا أَنَسٌ، قَالَ حَدَّثَنِي أَبُو بَكْرٍ ـ رضى الله عنه ـ قَالَ كُنْتُ مَعَ النَّبِيِّ صلى الله عليه وسلم فِي الْغَارِ، فَرَأَيْتُ آثَارَ الْمُشْرِكِينَ قُلْتُ يَا رَسُولَ اللَّهِ، لَوْ أَنَّ أَحَدَهُمْ رَفَعَ قَدَمَهُ رَآنَا‏.‏ قَالَ ‏ "‏ مَا ظَنُّكَ بِاثْنَيْنِ اللَّهُ ثَالِثُهُمَا ‏"‏‏.‏
Reference : Sahih al-Bukhari 4663
In-book reference : Book 65, Hadith 185
USC-MSA web (English) reference : Vol. 6, Book 60, Hadith 185
  (deprecated numbering scheme)