The Messenger of Allah, salla Allahu alaihi wa sallam gives us the answer!
Upon the authority of al-Bara’ ibn `Aazib who said: We went out with the the Prophet (SAWS) to a burial of a man from the Ansar (original inhabitants of Madina) until we arrived at the grave, and he still had not been placed in the slot of the grave.
Then the Messenger of Allah (SAWS) sat down and we sat around him. You would have thought that birds were upon our heads from our silence, and in the hand of the Messenger of Allah (SAWS) was a stick which he was poking the ground with. [Then he started looking at the sky and looking at the earth and looking up down three times]. Then he said to us: “Ask Allah for refuge from the torment of the grave”, he repeated this command two or three times. [Then he said O Allah I seek refuge in you from the torment of the grave] [three times]. Then he said: “Verily, the believing servant, when leaving this life and journeying to the hereafter angels will descend upon him, their faces will be white as if they were suns, they will have with them a shroud (kafan) from the shroud of Paradise), and an embalmment (HanouT) from the embalmments of heaven. Then, they will sit within eye-shot of him.
Then the angel of death (peace be upon him) will come and sit at his head and will say “O you virtuous soul; come out to a forgiveness and a pleasure from your Lord “. So it will come out as a drop comes out of the mouth of a jug (with ease), then he will take it, not leaving it in his hand for longer that a blink of an eye until they (he and the other angels) have placed it in that shroud and that embalmment. And there will emanate from it a smell like that of the most sweet smelling musk on the face of the earth. Then they shall ascend with it, and they shall not pass with it by any group of angels but they will say: What is this good and sweet-smelling soul?. Then they shall say to them (he is) “such” the son of “such” choosing the best of the names he used to be called in this life. Until they reach the lowest sky, then they shall ask permission to enter, and they shall be granted entry, until they end at the seventh heaven sky, then Allah, exalted and high, shall say: “write the book of my servant in `illiyeen (1) [And what will explain to you what Illiyeen is `illiyeen, there is a register fully inscribed to which bear witness those nearest to Allah (see 83:18)], and his book will be written in `illiyeen, and the shall be said “return him to the earth, for [I promised them] I have created them from it, and into it I shall return them, and from it I shall extract (resurrect) them a second time (20:55)”. So [he is returned to earth and] his soul is returned to his body [he said and he will hear the footsteps of his friends who buried him when they leave him].
Then two [severe] angels shall come and [terrify him and] sit him up next to them and shall ask him: “Who is your Lord?”. He shall reply “My Lord is Allah”. Then they shall ask him: “What is your religion?”. He shall answer them: “My religion is Islam”. Then they shall ask him “Who is this man who was sent among you?”. He will reply “He is the Messenger of Allah (SAWS) peace be upon him”. Then they shall ask him “What have you done?”. He shall reply: “I read the book of Allah, then I believed in it and accepted it”. [The angel will terrify him and ask him “who is your Lord?”, “what is your religion?” “who is your prophet?”, and this will be the last trial on earth for the believer, it is then when Allah says : “Allah will establish in strength those who believe with the word that stands firm in this world”, so he will answer my Lord is Allah, my religion is Islam and my Prophet is Mohammad salla Allahu alaihi wa sallam. Then a caller will call from the sky: “My slave has spoken the truth, so spread out for him from the heaven, and clothe him from the heaven, and open a door for him from the heaven (within his grave)”, so it’s goodness and its smell will come unto him, then his grave will be expanded for him as far as he can see.
Then a man will come to him. His face will be handsome, and his clothes will be handsome, and his smell will be sweet. Then he shall say unto him: I bring you glade tidings of that which will make you happy [Rejoice with a pleasure of Allah and delights that endure]. This is the day that you were promised (46:16). Then he will say [and may Allah give you glad tiding] “who are you?, for your face is the face of someone who comes with good news”. He shall reply: “I am your good deeds, [by Allah, I did not know of you but that you were quick to the obedience of Allah and slow to His disobedience, so may Allah reward you good]”. Then he shall say: “My Lord bring the hour so that I might return to my family and my wealth” [it will be said to him “be tranquil”].
He (Mohammed, salla Allahu alaihi wa sallam) said: { And the disbelieving [transgressor/wicked] servant}, if he is leaving this life and journeying to the hereafter then angels will descend upon him, their faces will be black, they have with them a coarse woolen fabric (sackcloth)[ made of fire]. Then they will sit within eye-shot of him. Then the angel of death will come and sit at his head and will say “O you wicked soul; come out to a anger from your Lord and a fury (from Him)”. So it will be distributed (spread out) throughout his body, then it will be ripped away as a skewer/spit is ripped out of damp cotton [and in its way out it will tear and cut the nerves and blood vessels] [and then he will be cursed by all the angels between the earth and the sky and by all the angels in the sky, and the gates of heaven are closed. There is no gate in the heaven but its people supplicate that the wicked soul shall not be ascended to their side], then he will take it (the soul), not leaving it in his hand for longer than a blink of an eye until they have placed it in that sackcloth. And there will emanate from it a stench like that of the most evil smelling corpse on the face of the earth. Then they shall ascend with it, and they shall not pass with it by a group of angels but they will say: What is this wicked soul?. Then they shall say to them (he is) “such” the son of “such” choosing the most hated of the names he used to be called in this life. Until they reach the lowest heaven (sky), then they shall ask permission to enter, and they shall not be granted entry. Then the Messenger of Allah (SAWS) recited “The doors of the sky are not opened to them, nor shall they enter heaven until the camel passes through the eye of the needle” (7:40).
Then Allah, exalted and high, shall say: “write the book of my servant in Sijjeen (2)(83:7) in the lowest earth”. [Then will be said “return my slave to the earth, for I promised them I have created them from it, and into it I shall return them, and from it I shall extract (resurrect) them a second time (20:55)”]. Then his soul shall be taken away [from the sky] with a mighty hurl [until it is cast into his body]. Then he (the Prophet salla Allahu alaihi wa sallam) read: “and those who associate partners with Allah, They are as one who falls from the sky then is snatched by the birds or is cast by the wind into a very low place (22:31)”. Then his soul will be returned into his body, [he (the prophet) said : verily he will hear the footsteps of his friends who buried him when they leave him]. Then two harsh severe and fearsome angels shall come and [terrify him and] sit him up and shall ask him: “Who is your Lord?”. He shall reply “Huh?, Huh (this is an expression of sorrow), I don’t know”. Then they shall ask him: “What is your religion?”. He shall answer them: “Huh?, Huh?, I don’t know”. Then they shall ask him “Who is this man who was sent among you?”. He will reply “Huh?, Huh?, I don’t know [I heard people saying that!]”. He (the Prophet salla Allahu alaihi wa sallam) said “And then will be said to him don’t ever know and don’t ever recite!”].
Then a caller will call from the sky: “My slave has spoken falsely, so spread out for him from the hell fire, and open a door for him from the hell fire (within his grave)”, so its heat and hot wind will come unto him, then his grave will be contracted upon him until his limbs are caught up among one another. Then a man will come to him. His face will be ugly, and his clothes will be ugly, and his smell will be vile. Then he shall say unto him: I bring you tidings of that which will harm you. This is the day that you were promised (70:44). Then he will say [and you, may Allah give you bad tiding] “who are you?, for your face is the face of someone who comes with evil”. He shall reply: “I am your evil deeds [by Allah, I did not know of you but that you were quick to the disobedience of Allah and slow to His obedience, so may Allah reward you bad, and then will be assigned to him a blind, deaf and mute person who holds in his hand a hammer, if a mountain is hit with it, it would disintegrate, and he will beat him with it until he becomes dust, and then Allah will render him to his initial form, and he will beat him again, and he (the wicked) will cry of sorrow and pain a cry that will be heard by all creatures except humans and jinn, and a door of hell will be opened unto him within his grave and will spread out for him sheets of hell fire]”. Then he shall say: “My Lord do not bring the hour”.
This hadith is narrated by Ahmad Ibn Hambal, Abu Dawud, Ibn Majah, at-Tayalisi, and al-Hakim who said it is according to the standards of Bukhari and Muslim. This text is the text of Ahmad, all text between brackets is from the other narrators and other narrations of Ahmad.
Notes
(1) `illiyin: comes from the root word of `uluww which means highness. It is a place in the (highest) seventh sky where the souls of the believers are gathered (Ibn `Abbas), it also carries the meaning of a very high and wide place (Ibn Kathir).
(2) Sijjin: comes from the root word of sijn which means narrowness. It is a place in the (lowest) seventh earth where the souls of the unbelievers are gathered (Ibn `Abbas), it also carries the meaning of a very low and narrow (Ibn Kathir).
Reading the previous hadith one may think that the punishment of the grave is reserved only for those who did not believe in Allah or associated with him someone else in worship, lordship, creation or in his names and attributes. It is not the case! the following authentic hadith tells us more! so let us read it carefully : Ibn Abbas (Radiya Allahu `anhuma) says that the Messenger of Allah, salla Allahu alaihi wa sallam, once, while passing by two graves, remarked : The inmates of these two graves are being tortured not for any serious sins, but in fact they are serious sins. One of them used to carry tales [gossiping] (nameemah) and the other used not to yastatir (1) when urinating. [Bukhari and Muslim]
(1) yastatir means both not covering or hiding himself from the sights of others as well as not cleaning himself after urinating.islamicsites.com