The Prophet ﷺ used to perform itikaf during the last ten days of Ramadan. One year he did not perform itikaf, so the following year he performed itikaf for twenty days.
كان النبي ﷺ يعتكف في العشر الأواخر من رمضان. فلم يعتكف عاما، فلما كان العام المقبل اعتكف عشرين.
Tirmidhi (803), Ibn Khuzayma (2226, 2227), Ibn Hibban (3664), and Hakim (1/439) all narrated it from the hadith of Ibn Abu Adi, from Humayd, from Anas, and he mentioned it. Its isnad is sahih. Tirmidhi said, hasan sahih gharib. Hakim said, "Sahih according to the conditions of the two Shaykhs."