Tahiyyatul Masjid: Two Rak'ahs on Entering the Masjid
Two rak'ahs prayed by a person who enters the masjid, before he sits down.
Abu Qatadah said that the Messenger of Allah (peace be upon him) said:
إِذَا دَخَلَ أَحَدُكُمُ الْمَسْجِدَ فَلَا يَجْلِسْ حَتَّى يُصَلِّيَ رَكْعَتَيْنِ
When one of you enters the masjid, let him not sit until he has prayed two rak'ahs.
This is in Sahih al-Bukhari 1163.
How it is prayed
Two rak'ahs like other voluntary prayers of two rak'ahs. The hadith names no surahs and no special manner. The prayer is tied to entering and sitting: a person who enters prays before he sits. For hurrying through them while the imam is speaking, see the section below and the page Jummah prayer.
When the imam is giving the sermon
Jabir said that Sulayk al-Ghatafani came on Friday while the Prophet was giving the sermon. The Prophet said to him: "When one of you comes on Friday while the imam is giving the sermon, let him pray two rak'ahs and keep them short" (Sahih Muslim 875). The full text is on the Jummah page.
Questions about tahiyyatul masjid
What is the ruling on tahiyyatul masjid?
The words of the hadith are "let him not sit until he prays two rak'ahs", which is a prohibition on sitting before praying. The dua said on entering the masjid is on the page dua for entering the masjid.
Can I pray it after Asr?
Abu Said reported that the Prophet said: "There is no prayer after Asr until the sun sets" (Sahih al-Bukhari 586). The three times mentioned by Uqbah ibn Amir are on the page Zawal prayer (Sahih Muslim 831). Whether prayers with a cause are prayed in these times is a matter for the books of fiqh.
What is recited in it?
The hadith names no surahs.
Is it prayed every time I enter the masjid?
The words are "when one of you enters the masjid", which is general for everyone who enters.