In the United States, a nonprofit organization that has received recognition of exemption under Section 501(c)(3) of the Internal Revenue Code generally does not pay federal income tax—including tax on capital gains—on gains from the sale of investments or other property, provided the gain is not from debt-financed property, is not unrelated business taxable income, and the organization continues to qualify for exemption. That is the condition that matters: "tax-exempt" is not an absolute status but a set of conditions, and capital gains are one place where those conditions can fail.
The baseline rule: exemption covers investment gains
A 501(c)(3) organization—a charity, private foundation, religious body, educational institution, and similar entities—is exempt from federal income tax under IRC §501(a). When such an organization sells stock, bonds, mutual fund shares, or real estate held for investment and realizes a gain, that gain is generally not subject to federal income tax. This applies to private foundations as well as public charities; both can hold endowments and rebalance portfolios without federal income tax on the appreciation, though private foundations face a separate excise tax on net investment income (historically 1.39%, with a reduced rate for foundations meeting certain distribution requirements—confirm the current figure and rules with the IRS or a tax adviser).
The logic is structural. Exemption is granted to organizations operated exclusively for exempt purposes, where no part of net earnings inures to the benefit of private individuals. Investment income that supports the mission fits that model. The organization is not a taxable "person" for these purposes in the way an individual or for-profit corporation is.
Where the exemption stops: three major exceptions
The baseline rule is often stated too broadly. Three categories of capital gain can be taxable even for a recognized 501(c)(3).
1: Unrelated business taxable income (UBTI)
If the property sold was used in a trade or business that is regularly carried on and not substantially related to the exempt purpose, the gain can be UBTI and subject to tax under IRC §§511–514. The classic illustration is a charity that operates a commercial business—say, a thrift store run on business lines, or a gift shop selling merchandise unrelated to its mission. Gains from assets used in that business can be taxable. Investment activity itself is generally not a trade or business for this purpose, which is why endowment gains usually escape UBTI; but the analysis is fact-specific, and activities financed with debt or conducted with commercial regularity can change the answer.
2: Debt-financed property
Under IRC §514, a portion of gain from the sale of property acquired or improved with acquisition indebtedness is treated as UBTI. A charity that buys a building with a mortgage and later sells it at a gain may owe tax on the debt-financed percentage of that gain, even though a debt-free sale of the same building would be exempt. This is one of the most frequently missed exceptions.
3: Private foundation excise tax on net investment income
Private foundations do not pay income tax on capital gains as such, but they do owe an excise tax on net investment income, which includes capital gains. The practical result is that a private foundation's realized gains reduce the foundation's resources by the excise rate, even though no income tax return line shows "capital gains tax." Public charities are not subject to this excise tax, though they may face the UBTI rules above.
Other entity types: "nonprofit" is not one thing
The question's phrase "nonprofits" covers a wide range of organizations, and the answer differs by category.
501(c)(3) charitable organizations: exempt from federal income tax on investment gains, subject to the exceptions above. Donors get deductions; the organization is subject to rules on private benefit, lobbying, and political activity. 501(c)(4) social welfare organizations, 501(c)(6) trade associations, 501(c)(7) social clubs, and similar: also generally exempt from income tax, but the details differ—for example, 501(c)(7) clubs face special rules on nonmember income, and 501(c)(4) organizations have their own UBTI analysis. State tax treatment varies. State and local taxes: federal exemption does not automatically confer state income tax exemption, property tax exemption, or sales tax exemption. Each state has its own qualification process and its own rules for capital gains, and some states tax investment income of exempt organizations differently. Unincorporated associations and trusts: a charitable trust may be taxed differently from a charitable corporation, and the trust's governing instrument and state law matter.
A common confusion is treating "501(c)(3) status" as identical to "tax-exempt" in every jurisdiction and for every tax. It is not. Recognition is federal; state treatment is separate.
Capital gains versus unrelated business income: a worked distinction
Suppose a museum (a 501(c)(3)) holds a diversified endowment and sells appreciated stock, realizing a $500,000 long-term gain. This is investment activity, not a regularly carried-on trade or business, and the stock was not debt-financed. The gain is generally not subject to federal income tax. The museum reports the sale on Form 990 (or 990-PF if a private foundation), but the gain does not generate a federal tax liability as capital gain.
Now suppose the same museum buys a commercial building with a mortgage, rents it to tenants at market rates, and sells it years later at a $500,000 gain. The rental activity may be an unrelated trade or business, and the acquisition indebtedness triggers §514. A portion of the gain—roughly the debt-financed percentage—can be UBTI, reported on Form 990-T, and taxed at corporate rates. The same dollar amount of gain produces a different tax result because of how the property was used and financed. That contrast is the core of the rule.
Why the confusion persists
Three sources of ambiguity are worth naming.
First, "capital gains tax" is a phrase associated with individuals. Nonprofits do not file individual returns and do not have a capital gains rate schedule in the way individuals do. When commentators say nonprofits "don't pay capital gains tax," they usually mean the gain is excluded from the exempt organization's income tax base—which is accurate for the baseline case but hides the UBTI and excise-tax exceptions.
Second, the exemption is organizational, not transactional. An exempt organization can have taxable income (UBTI) while remaining exempt. The organization does not lose its 501(c)(3) status merely because it owes tax on unrelated business income; it files Form 990-T and pays the tax. This trips up people who assume any tax liability means loss of exemption.
Third, private foundations are exempt but subject to the excise tax on net investment income, so the practical economics differ from public charities even though both are "tax-exempt." The distinction between "exempt from income tax" and "pays no tax on investment gains" is real.
What the answer does not cover
This is a federal-income-tax answer for the United States as of the reference date. It does not resolve state income tax, property tax, or sales tax treatment, which vary by state and locality. It does not address the excise tax rate applicable to a particular private foundation year, which should be confirmed against current IRS guidance. It does not address non-U.S. jurisdictions, where "nonprofit" and "charity" have different legal meanings and different capital gains rules. And it does not address the separate question of whether a particular organization's investment activity is sufficiently commercial to create UBTI—that is fact-specific and depends on the organization's activities, financing, and regularity.
For an organization actually facing a sale, the operative questions are: What is the entity's exemption category? Was the property debt-financed? Was it used in a regularly carried-on unrelated trade or business? Is the entity a private foundation subject to the investment-income excise tax? And what does the applicable state say? Those four questions, not the general label "nonprofit," determine the result.
Frequently asked questions
Does a 501(c)(3) pay tax on stock gains? Generally no, if the gain is from investment activity and not debt-financed or connected to an unrelated trade or business. It reports the gain on its information return but does not owe federal income tax on it in the baseline case.
Can a nonprofit lose its exemption by realizing capital gains? No. Realizing investment gains does not by itself jeopardize exemption. Problems arise from private benefit, excess benefit transactions, political activity, or operating for non-exempt purposes—not from selling appreciated investments.
Do private foundations pay capital gains tax? They are exempt from income tax but owe an excise tax on net investment income, which includes capital gains. The rate and any reduced-rate eligibility should be confirmed with current IRS guidance.
Is the answer the same for a 501(c)(4) or a social club? Broadly similar in structure—exempt from income tax, with UBTI rules—but the specifics differ by category, and state treatment varies. The general principle holds; the details do not transfer automatically.
What about selling a building the charity uses for its own programs? A sale of property used directly in the exempt function is generally not UBTI, and gain is generally exempt, subject to the debt-financed rules if there is a mortgage. The use of the property, not just the identity of the seller, matters.
The short version: exemption generally covers capital gains, but the exceptions—UBTI, debt-financed property, and the private foundation excise tax—are where the real analysis lives, and state law is a separate inquiry.