The guidance of the Prophet (peace be upon him) with regard to i`tikaf was the most perfect and moderate of guidance.
Once he observed i`tikaf in the first ten days of Ramadan, then in the middle ten days, seeking Laylat Al-Qadr (The Night of Decree). Then he was told that it is in the last ten days, so then he always observed i`tikaf during the last ten days, until he met his Lord.
On one occasion, he did not observe i`tikaf during the last ten days, so he made it up in Shawwal and observed i`tikaf during the first ten days thereof. This was narrated by Al-Bukhari and Muslim. In the year in which he died, he observed i`tikaf for twenty days. (Al-Bukhari)
It was said that the reason for that is that he knew his life was drawing to a close, so he wanted to increase his good deeds, to show his ummah how to strive hard in doing good deeds when the opportunity for doing so drew to close, so that they could meet Allah in the best way.
And it was said that the reason was that Jibreel used to review the Qur’an with him once each Ramadan, but in the year in which he died, he reviewed it with him twice, which is why his i`tikaf was twice as long as usual.
A more likely reason is that he observed i`tikaf for twenty days in that year because the year before he had been traveling. This is indicated by the report narrated by al-Nasa’i and Abu Dawud, and classed as sahih by Ibn Hibban and others, from Ubay ibn Ka`b who said: The Prophet (peace be upon him) used to observe i`tikaf during the last ten days of Ramadan, but he travelled one year and did not observe i`tikaf, so the following year he observed i`tikaf for twenty days. (Ibn Hajar, Fath al-Bari)
The Prophet (peace be upon him) used to order that a kind of tent be pitched for him in the mosque, and he would stay in it, keeping away from people and turning to his Lord, so he could be on his own with his Lord in a true sense of the word.
On one occasion, he observed i`tikaf in a small tent, and put a reed mat over the door. (Muslim)
Ibn al-Qayim said in Zad Al-Ma`ad:
All of this to achieve the spirit and purpose of i`tikaf, and is the opposite of what the ignorant do, whereby the place of i`tikaf becomes a place of gathering and meeting with people and chatting to them. This is one thing, and i`tikaf as observed by the Prophet (peace be upon him) is something else.
He used to stay in the mosque the whole time, and did not leave it except to relieve himself. ‘A’ishah (may Allah be pleased with her) said: “He would not enter his house for anything except for a need when he was observing i`tikaf.” (Al-Bukhari)
According to a report narrated by Muslim: “Except for human needs.” Al-Zuhri interpreted this as referring to urination and defecation.
He (peace be upon him) made sure he remained clean. He would lean his head out of the mosque into ‘A’ishah’s apartment so that she should wash his head and comb his hair.
‘A’ishah (may Allah be pleased with her) said: “The Prophet (peace and blessings of Allah be upon him) used to lean his head towards me when he was observing i`tikaf in the mosque, and I would comb his hair, when I was menstruating.” (Agreed Upon)
Al-Hafizh said: “This hadith indicates that it is permissible to clean oneself, put on perfume, wash oneself, comb one’s hair etc. (when in i`tikaf). The majority of scholars are of the view that nothing is makruh except that which it is makruh to do in the mosque.
When he was in i`tikaf, the Prophet (peace be upon him) did not visit the sick or attend funerals. This was so that he could concentrate fully on conversing with Allah and achieving the purpose of i`tikaf, which is to cut oneself off from people and turn to Allah.
‘A’ishah said: The Sunnah is for the person in i`tikaf not to visit the sick or attend funerals, or to be intimate with his wife. But there is nothing wrong with his going out for essential needs. (Authenticated by Al-Albani) “or to be intimate with his wife” means intercourse. This was stated by Al-Shawkani in Nail al-Awtar.
Some of his wives used to visit him when he was in i`tikaf.
It was narrated from Safiyiah, the wife of the Prophet (peace be upon him), that she came to the Messenger of Allah (peace be upon him) and visited him when he was in i`tikaf in the mosque, during the last ten days of Ramadan. She spoke with him for a while, then she stood up to leave. The Prophet (peace be upon him) stood up with her to take her home. (Agreed Upon)
In conclusion, his i`tikaf was moderate and not harsh. He spent all his time remembering Allah and turning to Him in worship, seeking Laylat Al-Qadr.