Except as otherwise provided in this section, in the case of a taxpayer who is an individual or an S corporation, no deduction otherwise allowable under this chapter shall be allowed with respect to the use of a dwelling unit which is used by the taxpayer during the taxable year as a residence.
Subsection (a) shall not apply to any deduction allowable to the taxpayer without regard to its connection with his trade or business (or with his income-producing activity).
Subsection (a) shall not apply to any item to the extent such item is allocable to space within the dwelling unit which is used on a regular basis as a storage unit for the inventory or product samples of the taxpayer held for use in the taxpayer’s trade or business of selling products at retail or wholesale, but only if the dwelling unit is the sole fixed location of such trade or business.
Subsection (a) shall not apply to any item which is attributable to the rental of the dwelling unit or portion thereof (determined after the application of subsection (e)).
Subsection (a) shall not apply to any item to the extent that such item is allocable to the use of any portion of the dwelling unit on a regular basis in the taxpayer’s trade or business of providing day care for children, for individuals who have attained age 65, or for individuals who are physically or mentally incapable of caring for themselves.
If a portion of the taxpayer’s dwelling unit used for the purposes described in subparagraph (A) is not used exclusively for those purposes, the amount of the expenses attributable to that portion shall not exceed an amount which bears the same ratio to the total amount of the items allocable to such portion as the number of hours the portion is used for such purposes bears to the number of hours the portion is available for use.
For purposes of applying subsection (c)(5) to deductions allocable to a qualified rental period, a taxpayer shall not be considered to have used a dwelling unit for personal purposes for any day during the taxable year which occurs before or after a qualified rental period described in subparagraph (B)(i), or before a qualified rental period described in subparagraph (B)(ii), if with respect to such day such unit constitutes the principal residence (within the meaning of section 121) of the taxpayer.
In any case where a taxpayer who is an individual or an S corporation uses a dwelling unit for personal purposes on any day during the taxable year (whether or not he is treated under this section as using such unit as a residence), the amount deductible under this chapter with respect to expenses attributable to the rental of the unit (or portion thereof) for the taxable year shall not exceed an amount which bears the same relationship to such expenses as the number of days during each year that the unit (or portion thereof) is rented at a fair rental bears to the total number of days during such year that the unit (or portion thereof) is used.
The term “dwelling unit” does not include that portion of a unit which is used exclusively as a hotel, motel, inn, or similar establishment.
In the case of an S corporation, subparagraphs (A) and (B) of subsection (d)(2) shall be applied by substituting “any shareholder of the S corporation” for “the taxpayer” each place it appears.
Nothing in this section shall be construed to disallow any deduction allowable under section 162(a)(2) (or any deduction which meets the tests of section 162(a)(2) but is allowable under another provision of this title) by reason of the taxpayer’s being away from home in the pursuit of a trade or business (other than the trade or business of renting dwelling units).