The Messenger of Allah ﷺ used to observe spiritual retreat during the last ten days of Ramadan. One year he traveled and did not observe the retreat, so the following year he observed it for twenty days.
أن رسول الله ﷺ كان يعتكف في العشر الأواخر من رمضان، فسافر ولم يعتكف، فلما كان من العام المقبل اعتكف عشرين يوما.
Reported by Abu Dawud (2463), Ibn Majah (1770), and Ahmad (21277), and graded sahih by Ibn Khuzayma (2225), Ibn Hibban (3663), and Hakim (1/439), all of them via Hammad bin Salama, from Thabit Bunani, from Abu Rafi, who is Nufay the Goldsmith, from Ubayy bin Kaab, who narrated it.