Sunan Abi Dawud Book 14, Hadith 153
The Prophet (ﷺ) used to observe I'tikaf during the last ten days of Ramadan. Nafi' said: 'Abd Allah (b. 'Umar) showed me the place in the mosque where Messenger of Allah (ﷺ) used to observe I'tikaf.
When the Messenger of Allah (ﷺ) intended to observe I'tikaf, he prayed the fajr prayer and then entered his place of seclusion. Once he intended to observe I'tikaf during the last ten days of Ramadan. She said: He ordered to pitch a tent for him, and it was pitched. She said: The other wives of the Prophet (ﷺ) also ordered to pitch tents for them and they were pitched. When he offered the fajr prayer, he saw the tents, and said: What is this ? Did you intend to do an act of virtue ? She said: He then ordered to demolish his tent, and it was demolished. Then his wives also ordered to demolish their tents and they were demolished. He then postponed I'tikaf till the first ten days, that is of Shawwal.
Abu Dawud said: This tradition has been transmitted by Ibn Ishaq and al-Auza'i from Yahya b. Sa'id in a similar manner, and Malik narrated it from Yahya b. Sa'id, saying: He observed I'tikaf during twenty days of Shawwal.
The Prophet (ﷺ) used to observe I'tikaf during ten days of Ramadan every year. But when the year in which he died, he observed I'tikaf for twenty days.