It is forbidden to say or think about sacred matters in a place that contains feces or other foul-smelling substances, as the Torah states: “You will return and cover your excrement. This is because Lord your God walks among you in your camp…. Your camp must therefore be holy” (Devarim 23:14-15). This law contains many details, and we will learn only a few of them.
Anything within four amot (c. two meters) of a person is considered to be within her “camp.” Hence, if there is excrement within her four amot, her camp is not holy and she may not pray there. If the excrement is in front of her, as long as she sees it, she may not pray. If the smell spreads, she must distance herself four amot from the place where the smell dissipates. Even one whose sense of smell is impaired must distance herself, like one who smells the odor (SA 79:1).
This law applies to anything rancid whose stench revolts people. Thus, one must distance herself from a carcass and from malodorous animal dung just as she must distance herself from human feces (MB 79:23). Foul-smelling vomit has the same status as excrement, but if it does not stink, some rule leniently and do not consider it like feces (see MB 76:20 and Ishei Yisrael 51:12).
When the odor spreads to another domain, for example, from the bathroom into the next room, one may not recite sacred words anywhere that the smell pervades. Some poskim are stringent and maintain that even when the foul odor comes from another domain, one must move four amot away from the place where the smell ends, and le-khatĥila this opinion is worth following (MB 79:17 and Kaf Ha-ĥayim 79:1; Peninei Halakha: Prayer, ch. 3 n. 10).