The Messenger of Allah ﷺ said, "Divide the inheritance among those entitled to fixed shares according to the Book of Allah, and whatever the fixed shares leave goes to the nearest male heir."
حدثنا العباس بن عبد العظيم العنبري حدثنا عبد الرزاق أنبأنا معمر عن ابن طاوس عن أبيه
قال رسول الله ﷺ اقسموا المال بين أهل الفرائض على كتاب الله فما تركت الفرائض فلأولى رجل ذكر
Bukhari narrated it in the Book of Inheritance, chapter "Inheritance of the Child from His Father and Mother," no. 6732, 6735, 6746, from the hadith of Abdullah bin Tawus, with this wording. Muslim also narrated it in the Book of Inheritance, chapter "Give the Shares of Inheritance to Those Entitled to Them, and What Remains Goes to the Nearest Male Relative," no. 1615, through the route of Abdul-Razzaq, with this wording.