Prophet Muhammad (pbuh) and Abu Bakr (RA) remained hidden in the cave for three consecutive days. Abu Bakr’s son would also spend the night nearby and walk to Makkah early in the morning to collect information about the activities of Quraysh, returning back to the cave to inform them in the evening. Abu Bakr’s slave would graze his goats near the cave so that both men could drink fresh milk.
Allah (SWT) sent a spider to spin a web across the entrance of the cave and two doves to build a nest and lay eggs. Meanwhile the Quraysh search party scoured the area close to the cave and would have found them hiding if looked in the cave but they went back after seeing the spider’s web and dove’s nest concluding that a person could not have entered the place. Finding Quraysh so close to the cave, Abu Bakr (RA) became very anxious about Prophet’s (pbuh) safety. The Prophet (pbuh) reassured him,
“How can you be apprehensive about two with whom is a third, especially when the third one is Allah?”
The above scene is also mentioned in the Quran in Surah Taubah:
“If ye help not (your leader), (it is no matter): for Allah did indeed help him, when the Unbelievers drove him out: he had no more than one companion; they two were in the cave, and he said to his companion, “Have no fear, for Allah is with us”: then Allah sent down His peace upon him, and strengthened him with forces which ye saw not, and humbled to the depths the word of the Unbelievers. But the word of Allah is exalted to the heights: for Allah is Exalted in might, Wise.” [9:40]
After three days on learning that Quraysh has returned back to Makkah, Prophet (pbuh) and Abu Bakr (RA) left the cave and headed to Madinah.