Positive commandment · Mitzvat Aseh #15 of 613
To affix a mezuzah
לִקְבֹּעַ מְזוּזָה
The verse · Devarim 6:9
וּכְתַבְתָּם עַל־מְזֻזוֹת בֵּיתֶךָ וּבִשְׁעָרֶיךָ
“And thou shalt write them upon the doorposts of thy house, and on thy gates.”
The Rambam’s words
To affix a mezuzah, as [Deuteronomy 6:9] states: "And you shall write them on the doorposts of your home."
לִקְבֹּעַ מְזוּזָה, שֶׁנֶּאֱמָר: "וּכְתַבְתָּם עַל מְזוּזֹת בֵּיתֶךָ וּבִשְׁעָרֶיךָ" (דברים ו ט; יא, כ).
Why · Sefer HaChinuch #423
To affix a mezuzah on entrances
“It is from the roots of the commandment that it serve as a memory device for a person about faith in G-d, every time he comes into his home and [when] he leaves [it], and like I wrote about the matter of tefillin.”
Who & when
“And it is practiced in every place and at all times by males and females.”
Where in the Mishneh Torah
Hilchot Tefillin, Mezuzah and the Torah Scroll הלכות תפילין ומזוזה וספר תורה