“and you shall write them on the doorposts of your house and on your gateways” (Devarim 6,9)
It is a positive commandment to affix a mezuza at the entrance of the home, as it says “and you shall write them on the doorposts of your house and on your gateways”. The idea of the mezuza is that we write two chapters from the Torah on one parchment and they are “Shema” until “U’visharecha” and the chapter of “Vehaya im shamoa” until “Kimei hashamayim al ha’aretz” and we fix it to the doorframe at the entrance of the house.
Amongst the roots of the commandment is that it is a reminder for a person of belief in Hashem each time he enters or exits his house. As Chazal say, one should fix it upon the top third of the doorframe, and it must be fixed in the tefach (see below) which is closest to the public domain, so that immediately upon his entrance to the house, he will come into contact with this commandment.
There are ten conditions necessary in a house for it to require a mezuza. 1) the house must be at least 4 amos by 4 amos square (see below). 2) it must have two doorposts 3) it must have a lintel 4) it must have a ceiling 5) it must have doors 6) the gateway needs to be at least ten tefachim (see below) 7) it must be a regular house (not a synagogue etc) 8) it should be made for human habitation 9) it should be made for honourable habitation 10) it should be made for permanent habitation.
N.B. For practical halacha, please consult a Rabbi
A house which has many different openings requires a mezuza to be fixed in every opening, even if he doesn’t regularly enter through them but uses only one of them. A room inside a house, even a room within another room, all the rooms require a mezuza, for they are all meant for habitation.
This commandment applies in every place, at every time, to men and to women. Once who builds a house and puts a ceiling on it and does not immediately fix a mezuza, or who hires a house and does not fix a mezuza, is transgressing this positive commandment, and even if the obligated time for the fixing of the mezuza has passed, he is warned that he is permanently obligated to fix it at every time that he lives in the house.