The foundation of the entire mitzva appears twice in the Torah: Devarim 6:9 and Devarim 11:20 both command that these words be inscribed "on the doorposts of your house and on your gates," and the Gemara (Menachot 44a) derives from this double formulation that one who lacks a mezuzah on his doorpost violates two positive commandments.
The Gemara's drashah in Yoma 11b establishes the three criteria that a space must satisfy to require a mezuzah: it must be designated for residence (like a house), used for dignified purposes, and be non-consecrated — thereby excluding a bathroom, a tannery, a bathhouse, and a mikveh room, as well as the Temple courts, which are holy rather than ordinary.
From this framework, Yoma 11a expands the obligation beyond the private home: a baraita derived from the word "and your gates" that the gates of houses, courtyards, cities, and towns all carry a distinct obligation of mezuzah — though the Gemara there notes a practical question about city gates whose openings do not clearly function as residential entrances.
The ten structural preconditions a dwelling must meet before the mitzva applies are enumerated identically by the Rambam (Mishneh Torah, Tefillin, Mezuzah and the Torah Scroll 6:1–4), Sefer HaChinukh (423:4), and Peninei Halakhah (Likkutim I 10:11): the space must measure at least four by four cubits, have two doorposts, a lintel, a roof, and doors, with an opening at least ten handbreadths high, and it must be a non-consecrated, permanent, human, and dignified dwelling.
The minimum-size requirement is confirmed by the Gemara (Sukkah 3a), which establishes that a house lacking four cubits by four cubits is exempt from mezuzah (alongside other house-related obligations), and Sukkah 8b supplies a concrete illustration: a potter's inner booth, being a permanent residence, is obligated in mezuzah, while his outer work booth, being non-permanent, is exempt.
The requirement of permanence is the basis on which the Arukh HaShulchan (Yoreh De'ah 286:25) — citing the Beit Yosef's ruling in Shulchan Arukh Yoreh De'ah 286:7 — exempts a sukkah during the festival, a house on a ship, and market stalls, since none of these constitute a fixed, permanent dwelling.
The obligation extends to every entrance made for entry and exit, not only the main door: the Kitzur Shulchan Arukh (11:1) rules that even if one has many rooms with many doorways and habitually uses only one, all doorways require a mezuzah — with the sole exception of an opening built exclusively for loading cargo when another doorway serves as the regular entrance.
Peninei Halakhah (Likkutim I 10:3) addresses the widespread misconception that only the main entrance requires a mezuzah, clarifying that every room in the house requires one on its doorway — but that rooms whose primary use is inherently undignified, such as bathrooms and shower rooms, do not receive a mezuzah because they fail the requirement of dignified dwelling.
For shared spaces, the Arukh HaShulchan (Yoreh De'ah 286:1) rules that partnership premises (where several Jews share a building) are obligated, but a room in which a Jew and a non-Jew reside together is exempt, per the Rema's ruling; he also notes that in his era the obligation on city gates is practically inapplicable since Jews no longer have exclusively Jewish districts.
A study hall presents a machlokes: Shulchan Arukh Yoreh De'ah 286:10 records that a beit midrash is exempt, but that if there is an entrance through which one regularly passes to one's home it requires a mezuzah on that doorway; a dissenting view holds that a beit midrash is always obligated, and the Shulchan Arukh rules one should follow that stringency without reciting a brachah.
Regarding placement, the Gemara (Menachot 33a–34a) establishes the core rules: the mezuzah must be on the right side upon entering, and when two rooms share a doorway and it is unclear which room is the interior one, one follows the indication of the hinge-socket — the room with the socket is the inner room, and the mezuzah goes on the right as one enters that room; the Gemara also records that the ideal vertical position is at the beginning of the upper third of the doorway's height.
Shulchan Arukh Yoreh De'ah 289:1 codifies all of this: the mezuzah is placed in a tube, affixed in the empty space of the doorway within the tefach closest to the outside, at the beginning of the upper third of the doorway's height, on the right side of the one entering — and if placed higher it remains valid so long as it is at least a tefach below the lintel; if placed on the left side it is invalid; and one who affixes multiple mezuzot recites a single brachah for all of them.
The Arukh HaShulchan (Yoreh De'ah 289) adds that whether one is left-handed or even left-footed makes no difference to which side is "right" — the house is built for all its residents, not for any particular individual, so the right side of the entrance is determined objectively.
B'Mareh HaBazak (IX:35) addresses the practical case of a room smaller than four by four cubits that opens onto a larger obligated room, noting that some hold a mezuzah should be affixed to the doorway between them on the right side of one entering the larger room; it also discusses a porch (mirpeset), recording a dispute about whether the mezuzah goes on the right of one exiting from the house onto the porch or on the right of one entering from the porch into the house.
On the time-sensitive question of when the obligation begins, Shulchan Arukh Yoreh De'ah 286:22 and the Gemara (Menachot 44a) agree: one who rents outside Eretz Yisrael or stays in a guesthouse in Eretz Yisrael is exempt for the first thirty days, after which the obligation applies; but one who rents in Eretz Yisrael must affix a mezuzah immediately, because of the mitzva of settling the Land.
Minchas Yitzchak (4:89) is not available in text for Mekoros to read, but our research indicates that he addresses whether a mezuzah must be affixed to a mikveh bathhouse and its auxiliary rooms, and which categories of non-residential space are thereby exempt, in this source.
Daat Kohen (179) is not available in text for Mekoros to read, but our research indicates that he addresses the requirement of mezuzah for a dwelling defined by analogy to a sukkah, and the placement of the mezuzah on the right side of an entrance from the public domain, including the case of an inner room within an outer room, in this source.
Shevet HaLevi (2:156) is not available in text for Mekoros to read, but our research indicates that he addresses whether a doorway with only a single post — rather than two doorposts — requires a mezuzah in this source.
Modern poskim have addressed this question directly. Our research indicates that Minchas Yitzchak (6:20) is relevant.