When should a person who is observing i’tikaaf during the last ten days of Ramadan enter i’tikaaf and exit from it?
Question

I want to observe i’tikaaf during the last ten days of Ramadan. I would like to know when I should enter the mosque and when I should exit therefrom.
Praise be to Allah.Firstly: 
With regard to entering the place of i’tikaaf, the majority of scholars (including the four imams Abu Haneefah, Maalik, al-Shaafa’i and Ahmad, may Allah have mercy on them) are of the view that the one who wants to observe i’tikaaf during the last ten days of Ramadan should enter his place of i'tikaaf before the sun sets on the night of the twenty-first. They quoted several texts as evidence, including the following: 
1 – It was proven that the Prophet (peace and blessings of Allah be upon him) used to observe i'tikaaf during the last ten nights of Ramadan, Agreed upon. This indicates that the period of i’tikaaf is counted by the nights, not the days. And Allah says (interpretation of the meaning): 
“And by the ten nights” [al-Fajr 89:2]
The last ten nights start with the twenty-first. 
Based on this, he should enter the mosque before the sun sets on the night of the twenty-first. 
2 – They (the scholars) said that one of the greatest aims of i'tikaaf is to seek Laylat al-Qadr, and the night of the twenty-first is one of the odd-numbered nights in the last ten nights of Ramadan, so it may possibly be Laylat al-Qadr, so he should be observing i’tikaaf on that night. This was stated by al-Sindi in Haashiyat al-Nasaa’i. 
See al-Mughni, 4/489. 
But al-Bukhari (2041) and Muslim (1173) narrated that ‘Aa’ishah said: When the Messenger of Allah (peace and blessings of Allah be upon him) wanted to observe i’tikaaf, he would pray Fajr then enter his place of i'tikaaf. 
Because of the apparent meaning of this hadeeth, some of the salaf were of the view that he would enter his place of i’tikaaf after Fajr prayer. This view was followed by the scholars of the Standing Committee (10/114) and Shaykh Ibn Baz (15/442). 
But the majority of scholars responded to this hadeeth in one of two ways: 
(1)That the Prophet (peace and blessings of Allah be upon him) had started i'tikaaf before the sun set, but he did not enter the place for i’tikaaf until after Fajr prayer
Al-Nawawi said: “When he wanted to observe i’tikaaf, he would pray Fajr then enter his place of i'tikaaf”  - this was quoted as evidence by those who say that i’tikaaf should be started at the beginning of the day. This is the view of al-Awzaa’i and al-Thawri, and of al-Layth in one of his two opinions. Maalik, Abu Haneefah, al-Shaafa’i and Ahmad said: he should enter (i’tikaaf) before the sun sets if he wants to observe i’tikaaf for a month or for ten days. They interpreted the hadeeth as meaning that he entered the place of i’tikaaf in order to be alone there after he prayed Fajr, not that this is the time when he began i’tikaaf; rather he was in i’tikaaf from before Maghrib and stayed in the mosque, and when he had prayed Fajr he withdrew to be by himself. 
(2)al-Qaadi Abu Ya’la, one of the Hanbalis, responded by interpreting the hadeeth as meaning that he (peace and blessings of Allah be upon him) used to do that on the twentieth. Al-Sindi said: This response is more likely to be correct.
Shaykh Ibn ‘Uthaymeen was asked in Fataawa al-Siyaam (p. 501): When does i’tikaaf begin? 
He replied: 
The majority of scholars are of the view that i’tikaaf should begin on the night of the twenty first, not from Fajr of the twenty-first, although some of the scholars are of the view that i’tikaaf should begin from Fajr of the twenty-first, based on the hadeeth of ‘Aa’ishah (may Allah be pleased with her) that was narrated by al-Bukhari: “When he had prayed Fajr he entered his place of i'tikaaf”. But the majority of scholars responded by stating that the Messenger (peace and blessings of Allah be upon him) withdrew from people in the morning, but the intention to observe i’tikaaf was formed at the beginning of the night, because the last ten nights start when the sun sets on the twentieth.  
He also said (p. 503): 
Entering the place of i’tikaaf for the last ten nights of Ramadan may be done when the sun sets on the night of the twenty-first, because that is the time when the last ten nights begin. This is not contradicted by the hadeeth of ‘Aa’ishah because the wording is different, so it should be understood according to what the language indicates. This is what was narrated by al-Bukhari (2041) from ‘Aa’ishah (may Allah be pleased with her) who said: The Messenger of Allah (peace and blessings of Allah be upon him) observed i’tikaaf every Ramadan and when he had prayed Fajr he would enter the place where he observed i’tikaaf. 
Her words “and when he had prayed Fajr he would enter the place where he observed i’tikaaf” indicate that he was already staying in the mosque, meaning that he was in the mosque before he entered he place of i’tikaaf. 
Secondly: 
With regard to coming out of i’tikaaf: 
He should come out when the sun sets on the last day of Ramadan. 
Shaykh Ibn ‘Uthaymeen was asked: When should a person come out of i’tikaaf? Is it after the sun sets on the night of Eid or after Fajr on the day of Eid? 
He replied: 
He should come out of i’tikaaf when Ramadan ends. Ramadan ends when the sun sets on the night of Eid. Fataawa al-Siyaam, p. 502. 
It says in Fatawa al-Lajnah al-Daa’imah, 10/441. 
The period of i’tikaaf during the (last) ten nights of Ramadan ends when the sun sets on the last day of the month. 
If he chooses to stay until he has prayed Fajr and then depart from his place of i’tikaaf to the Eid prayer, there is nothing wrong with that. Some of the scholars regarded that as mustahabb. 
Imam Maalik (may Allah be pleased with him) said that he saw that some of the scholars who had observed i’tikaaf during the last ten nights of Ramadan did not go back to their families until they had attended the (prayer of Eid) al-Fitr with the people. Maalik said: I heard that from the righteous people who have passed on, and this is the dearest to me of what I have heard about that. 
Al-Nawawi said in al-Majmoo’ (6/323): 
Al-Shaafa’i and his companions said: Whoever would like to follow the example of the Prophet (peace and blessings of Allah be upon him) in observing i’tikaaf during the last ten nights of Ramadan should enter the mosque before the sun sets on the night of the twenty-first, so that he will not miss any of it, and he should come out after the sun sets on the night of Eid, whether the month is twenty-nine days or thirty. It is better for him to stay in the mosque on the night of Eid so that he can offer the Eid prayer there, or go out to the Eid prayer-place if they pray Eid there. 
If he goes directly from i’tikaaf to the Eid prayer, it is mustahabb for him to do ghusl and make himself look good before going out, because this is one of the Sunnahs of Eid. For more information please see question no. 36442.