From the 2018 International Residential Code unless otherwise indicated.
R314.3 - Location
Smoke alarms shall be installed in the following locations:
In each sleeping room.
Outside each separate sleeping area in the immediate vicinity of the bedrooms.
On each additional story of the dwelling, including the basements and habitable attics and not including crawl spaces and uninhabitable attics. In dwellings or dwelling units with split levels, and without an intervening door between the adjacent levels, a smoke alarm installed on the upper level shall suffice for the adjacent lower level provided that the lower level is less than one full story below the upper level.
Smoke alarms shall be installed not less than 3 feet horizontally from the door or opening of a bathroom that contains a bathtub or shower unless this would prevent placement of a smoke alarm required by Section R314.3.