The Prophet ﷺ used to perform itikaf during the last ten days of Ramadan. One year he did not perform it, so the following year he performed itikaf for twenty days.
حدثنا محمد بن بشار حدثنا ابن أبي عدي قال أنبأنا حميد الطويل
كان النبي ﷺ يعتكف في العشر الأواخر من رمضان فلم يعتكف عاما فلما كان في العام المقبل اعتكف عشرين
[Sahih]. Ibn Khuzayma also narrated it, no. 2226, from Muhammad bin Bashshar, and Ahmad, 3/104, from the hadith of Muhammad bin Abu Adi through the same route. The hadith has many corroborating narrations in Bukhari, no. 2044, and elsewhere.There is also a narration on this topic from Abu Hurairah [Bukhari, no. 2044].