The Prophet ﷺ used to observe itikaf during the last ten days of Ramadan. One year he did not observe it, so the following year he observed itikaf for twenty nights.
حدثنا موسى بن إسمعيل حدثنا حماد أخبرنا ثابت عن أبي رافع
أن النبي ﷺ كان يعتكف العشر الأواخر من رمضان فلم يعتكف عاما فلما كان في العام المقبل اعتكف عشرين ليلة
Hadith: 1770, itikaf, Reference: [Its isnad is sahih] Ibn Majah narrated it in the Book of Fasting, the chapter on what has been mentioned regarding, from the narration of Hammad bin Salama, and Ibn Khuzayma graded it sahih, Hadith: 2225, as did Ibn Hibban, Hadith: 917, and Hakim, 1/439, and Dhahabi concurred with him.