The rule
Section 707.4 sets the locations. Every horizontal drainage pipe gets a cleanout at its upper terminal. A run more than 100 feet long in total developed length gets one for each 100 feet or fraction of it. Add one more for each aggregate horizontal change in direction over 135 degrees, which means turns are added up: a pair of 90 degree turns in one run counts, while a couple of gentle bends that add up to less than 135 don't.
A cleanout also goes above the fixture connection fitting serving each urinal, wherever the urinal is in the building.
There are exceptions. You can skip a cleanout on a horizontal drain shorter than 5 feet unless it serves sinks or urinals, and on a horizontal pipe on a slope of 72 degrees or less from vertical (a one-fifth bend). Except for the building drain, its horizontal branches, kitchen sinks and urinals, pipe above the floor level of the lowest floor doesn't need one. An approved two-way cleanout inside the building wall near the drain-to-sewer connection, or outside at the lower end of the building drain and extended to grade, can stand in for the upper terminal cleanout.
Cleanouts have to be watertight and gastight (707.3), and the fitting can't be smaller than Table 707.1 says: for 4 inch pipe and larger it's 3-1/2 inch. Floor covers and rims meant to take loads have to be rated for the load (707.4.1).
On the job
- Walk the run on the plans and count turns before you rough in. Cleanouts are cheapest as a wye and a plug while the pipe is open.
- A two-way cleanout near the foundation covers the upper end of the building drain, which is why you'll often see one just outside the house.
- Keep kitchen sink lines in mind. They're named in the exception, so a cleanout is expected even on an upper floor.
- A cleanout you can't reach doesn't count. Section 707.8 covers access and clearance, so don't box one into a wall without a cover plate.
The inspector and your city's adopted edition have the final word.