The Torah commands that we write "these words" on the doorposts of your homes, and upon your gates".(Deuteronomy 6:9). This has come down to us through the Oral Torah as meaning that a parchment scroll, hand written with intent (like a Torah scroll) must be affixed on the right side of every doorway in a Jewish home. It is to contain two paragraphs of the Torah, which speak of G-d's unity, the command to love and obey Him, to recite the Shma' every morning and night, as well as commanding the mitzvot of Mezzuzah and Terfillin. Mezzuzah literally means "doorpost". Nearly all Jews keep this mitzvah, at least partially.Writing a Mezzauzah takes nearly an hour in the Sepharadic script, two and a half hours in the Ashkenazic script. This can be somewhat pricey. As a result, many only put the Mezzuzah on the front door, rather than all doors, as commanded by the Torah. In addition, unscrupulous merchants often substitute either photocopied Mezzuzot, or those written in a crudely written, invalid script. The scroll is placed in a casing, which can be a simple paper wrapping, plastic, or even silver. The casing has no rules attached to it. (A Mezzuzah that is exposed to the elements should have a sturdy, waterproof case). The scroll is the main thing. We have a tradition that goes back at least a thousand years that the scroll is written in twenty two lines, and the Name of G-d, Shad-dai (Almighty) is written on the back.
Like other mitzvot, the Torah is silent as to the reason(s) for this mitzvah. Many rabbis have interpreted it as a sort of amulet, protecting the home and its occupants. in fact, in medieval France and Germany, names of angels were inscribed in the margins! (Especially to be found in RASHI and Machzor Vitri). Maimonides, and other philosophically inclined rabbis, decried this, as it is "transforming the symbol of G-d's unity into a magic amulet". The more mystically inclined counter that there are many references in the Talmud that ascribe a protective power to the Mezzuzah. The philosophers counter that these were statements that are either allegorical, or meant to excite the "common people". A compromise view, accepted by many (as well as yours truly) is that in the merit of the fulfillment of this mitzvah, G-d extends protection over us. (The actual object being powerless except through the power of G-d).The philosophers balk at even this, seeing the mitzvot as primarily reminders of G-d's presence, with no material meanings. In practice, no one today includes the names of angels in the Mezzuzah, although most (but not all!) communities include a mystical permutation of Divine Names , consisting of three words, on the back, in addition to the above mentioned Divine Name. Mystics and philosophers agree, however, that as we enter or leave our homes,we encounter the Mezzuzah (many even kiss it), and are aware of G-d's presence, what we need to take into the world, and what, upon returning home, we need to "leave at the doorstep".
Rabbi Samson Raphael Hirsch writes a powerful thought. Civilizations rise, civilization fall. When a society crumbles, the Jew picks the Mezzuzah out of the rubble, and affixes it at his next stop. Our real home is G-d!