The short answer
Three men trapped in cave: the Prophet Muhammad, peace be upon him, told it in Sahih al-Bukhari 2272. A rock sealed the cave, and each man asked Allah to relieve them by a deed he had done for Him alone. It is graded sahih (authentic), and a version is also in Sahih Muslim 2743.
Who were the three men?
The narration calls them "three men from among those who were before you." It gives no names, no town and no era beyond that phrase. The cousin, the first man's parents and the worker are not named either.
This is a different account from the People of the Cave in Al-Kahf 18:9 to 26. The men here are unnamed figures in a hadith, and the Quranic passage is about young believers. See the People of the Cave for that account. 1
The story in four pictures
1The rock
Three men entered a cave at night. A big rock rolled down and closed its mouth.
2The milk
The first man waited with the milk until his parents woke. The rock shifted a little.
3The gold
The second man turned from a sin and left the gold. The rock shifted a little more.
4The wage
He gave a worker his wage, grown into a herd. The rock shifted completely and they walked out.
What does the narration say?
The narration is reported by 'Abdullah ibn 'Umar, may Allah be pleased with him, who heard the Prophet Muhammad, peace be upon him, tell it. In the translation on sunnah.com, the men say to one another: "Nothing could save you from this rock but to invoke Allah by giving reference to the righteous deed which you have done" (English: sunnah.com, USC-MSA translation). 1
- The rock closes the cave. The Prophet said that three men set out together, reached a cave at night and entered it. A big rock rolled down the mountain and closed the mouth of the cave. They said that nothing could save them except calling on Allah by a righteous deed each had done. 1
- The first man. He had elderly parents, and he never gave milk to his household or his property before them. One day he was delayed, and came back after they had gone to sleep. He milked for them, but found them asleep. He disliked giving the milk to anyone before them, so he stood waiting with the bowl in his hand until dawn, when they woke and drank it. He asked Allah to relieve them, saying he had done this for Allah's sake. The rock shifted a little, but they still could not get out. 1
- The second man. He desired a cousin whom he loved more than anyone, but she refused him. In a year of famine she came to him in need, and he gave her 120 dinars on condition that she yield to him. When he was about to, she said it was illegal for him to outrage her chastity except by legitimate marriage. He drew back and left her, and left the gold. He asked Allah to relieve them, saying he had done this for Allah's sake. The rock shifted a little more, but they still could not get out. 1
- The third man. He had hired workers and paid each of them, except one who left without taking his wage. He invested that wage until it grew into much property. When the man returned and asked for his wages, he was shown the camels, cattle, sheep and slaves, which were all his. The man said not to mock him. The third man said he was not mocking him, and the worker took the whole herd and left nothing. The third man asked Allah to relieve them, saying he had done this for Allah's sake. The rock shifted completely, and they walked out. 1
Not stated in the narration: the men's names, their town, their era beyond "those who were before you," the cousin's name, and what kind of wage the worker was owed. This page does not supply them.
Where does it come from?
1AuthenticSahih al-Bukhari 2272
The record is Sahih al-Bukhari 2272 (sunnah.com/bukhari:2272), Book 37, Hadith 12. Sahih Muslim 2743a was compared with 2272 on sunnah.com (details below). Sahih al-Bukhari 2215, 2333, 3465 and 5974 have not been compared with 2272. The record gives the grade sahih for both Sahih al-Bukhari and Sahih Muslim. The stored English and Arabic were read on sunnah.com on 19 October 2026. 1
Do the versions differ?
Yes, in details. Sahih Muslim 2743a differs in these ways: rain drives the men to shelter; the first man's small children cry near his feet; the second man pays 100 dinars, and the report describes the effort of collecting them; the third man plants a measure of rice, and its yield becomes cattle and herders, which he gives to the worker. The short Arabic for 100 dinars is «بِمِائَةِ دِينَارٍ» and for the rice measure «بِفَرَقِ أَرُزٍّ». This page follows Sahih al-Bukhari 2272 only, and does not mix the versions. Where you read a retelling that gives other details, check which collection and number it follows. 1
What does it teach?
- That a person can call on Allah by a righteous deed done for His sake.
- Honouring parents, shown in the first man's care for them.
- Leaving a sin he could have committed, because he thought it a sin, shown in the second man.
- Honesty about what is owed to others, shown in the third man.
Each man names the same condition: that the deed was done for Allah's sake alone. 1
What does it not mean?
- It does not name the men, the place or the era beyond "those who were before you."
- It does not support seeking help through the dead or through another person's status. Each man asks through his own deed.
- It does not praise the second man's earlier intent. The narration reports that he walked away from the sin.
For a personal question about your own situation, ask a scholar you trust.
I heard the story of the three men in the cave when I was young, as a story about a rock and a way out. Reading the narration properly, what stayed with me is that each man named something he had done for Allah's sake when nobody was watching. That is the part I keep coming back to.
Try it: three questions
Pick an answer. Each one explains itself.
1What did each man call on Allah by?
Answer: A righteous deed he had done for Allah's sake. The narration says each man asked Allah by a righteous deed he had done for His sake.
2Which man left the gold he had given?
Answer: The second man. The second man had given his cousin 120 dinars. When she said it was unlawful except by legitimate marriage, he left her and the gold.
3How did the rock finally move?
Answer: It shifted completely after the third man called on Allah. The rock shifted a little after the first two men, and shifted completely after the third.
Questions people ask
Is this the same story as the People of the Cave?
No. The People of the Cave are in Al-Kahf 18:9 to 26, a Quranic account of young believers. This hadith is a separate narration about three unnamed men. The People of the Cave page covers the Quranic account.
Are the three men named?
No. The narration gives no names. It says only that they were three men from among those who were before you.
Which hadith is this story from?
Sahih al-Bukhari 2272, graded sahih. A version is also recorded in Sahih Muslim 2743, and that version differs in some details. This page follows the Bukhari text only.
Sources
Every claim on this page comes from one of these. Gradings are reported with the scholar's name; we do not grade hadith ourselves.
- 1
The Prophet told of three men from earlier peoples trapped in a cave by a fallen rock, who each called on Allah by a deed done sincerely for Him (honouring aged parents, refraining from unlawful intercourse, and faithfully returning a worker's grown wages), until the rock moved and they walked out.
Sahih al-Bukhari 2272 Book 37, Hadith 12
Authentic: in Sahih al-Bukhari
Next
Join the email list
New guides by email, now and then. No spam, and you can leave at any time.
Ilmwell is free and kept going by readers. See how to support it.