Bahz bin Hakim narrates from his father, and he from his father (may Allah be pleased with him), that he said: "O Prophet of Allah! From whom should we cover our private parts, and from whom need we not?" He (peace and blessings be upon him) said: "Cover your private parts from everyone except your wife or your slave woman." I said: "O Messenger of Allah! What if people are mixed together?" He (peace and blessings be upon him) said: "If you are able to ensure that no one sees your private parts, then do so." I said: "O Messenger of Allah! What if one of us is alone at home?" He (peace and blessings be upon him) said: "One should feel more shy before Allah than before people; He is more deserving of modesty."
Imam al-Bukhari (may Allah have mercy on him) has alluded to this hadith in his Sahih.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3213