عَنْ عَبْدِ اللَّهِ بْنِ سَعْدٍ أَنَّهُ سَأَلَ النَّبِيَّ صَلَّى اللَّهُ عَلَيْهِ وَآلِهِ وَسَلَّمَ عَنِ الصَّلَاةِ فِي الْبَيْتِ وَعَنِ الصَّلَاةِ فِي الْمَسْجِدِ فَقَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَآلِهِ وَسَلَّمَ: ((أَمَّا الصَّلَاةُ فِي الْمَسْجِدِ وَالصَّلَاةُ فِي بَيْتِي فَقَدْ تَرَى مَا أَقْرَبَ بَيْتِي مِنَ الْمَسْجِدِ، وَلَأَنْ أُصَلِّيَ فِي بَيْتِي أَحَبُّ إِلَيَّ مِنْ أَنْ أُصَلِّيَ فِي الْمَسْجِدِ إِلَّا أَنْ تَكُونَ صَلَاةً مَكْتُوبَةً))
It is narrated from Sayyiduna Abdullah bin Sa’d (may Allah be pleased with him) that he asked the Noble Prophet (peace and blessings be upon him) about prayer in the house and in the mosque. The Messenger of Allah (peace and blessings be upon him) said: Prayer in the mosque and prayer in the house—you see how close my house is to the mosque, but it is more beloved to me to pray in my house than to pray in the mosque, except if it is an obligatory prayer.