Selling investments inside your HSA does not create a taxable event. The IRS treats trades within a Health Savings Account the way it treats moves between your checking and savings accounts, so taxes on selling HSA investments are simply not a federal concern as long as the proceeds stay in the account. Tax consequences only appear when money actually leaves the HSA, and even then, withdrawals used for qualified medical expenses come out completely tax-free.
The Sale Itself Is Invisible to the IRS
When you sell a stock, mutual fund, or ETF held inside your HSA, no capital gains tax applies. Holding period doesn’t matter. Size of the gain doesn’t matter. Whether you made 5% or 500%, the growth stays sheltered while the money remains in the account.1Internal Revenue Service. Publication 969 (2025), Health Savings Accounts and Other Tax-Favored Health Plans
The trade-off is that losses inside the HSA don’t help you either. You can’t claim a capital loss deduction for an investment you sold at a loss inside the account. The IRS ignores what happens in the investment sub-account entirely. Funds simply convert from invested assets back into cash, ready for withdrawal or reinvestment.
This is what makes the HSA’s triple tax advantage work: contributions reduce taxable income, growth compounds without annual tax drag, and qualified withdrawals come out tax-free.1Internal Revenue Service. Publication 969 (2025), Health Savings Accounts and Other Tax-Favored Health Plans No other account in the tax code offers all three at once.
California and New Jersey Are Different
The federal shield on HSA investment growth does not extend to every state. California and New Jersey do not conform to the federal HSA rules. Residents of those two states must report HSA contributions as taxable income on their state returns, and interest, dividends, and capital gains earned inside the account are also subject to state income tax. California requires taxpayers to reverse the entire federal HSA treatment on the state return, so gains you’d never report federally still show up on your California filing.2California Franchise Tax Board. Bill Analysis, AB 781 – Health Savings Account (HSA) Deduction
Every other state with an income tax follows federal treatment, so HSA sales stay invisible on state returns for the vast majority of account holders. If you live in California or New Jersey, though, selling appreciated positions inside your HSA can produce a state tax bill even when nothing is owed federally.
When Withdrawals Are Tax-Free
Distributions from an HSA are tax-free when used for qualified medical expenses. The IRS defines these broadly: doctor visits, hospital bills, prescription drugs, dental work, vision care, deductibles, and copayments all qualify.3Internal Revenue Service. Publication 502 (2025), Medical and Dental Expenses Since the CARES Act took effect in 2020, over-the-counter medications and menstrual care products also qualify without a prescription.4Internal Revenue Service. IRS Outlines Changes to Health Care Spending Available Under CARES Act
The expense must have been incurred after you established the HSA. Anything you paid before opening the account doesn’t qualify, no matter how large the bill. You can also use HSA funds tax-free for qualified expenses incurred by your spouse and your tax dependents.1Internal Revenue Service. Publication 969 (2025), Health Savings Accounts and Other Tax-Favored Health Plans
Health insurance premiums generally do not qualify, with a few exceptions: COBRA continuation coverage, qualified long-term care premiums, and premiums paid while you’re receiving unemployment benefits all qualify for tax-free reimbursement.1Internal Revenue Service. Publication 969 (2025), Health Savings Accounts and Other Tax-Favored Health Plans
You Can Wait Decades to Reimburse Yourself
There is no deadline for taking a tax-free distribution. You can pay a $10,000 medical bill out of pocket today, let the HSA compound for 20 years, and then withdraw $10,000 tax-free. The only requirements are that the expense was incurred after the HSA was established and that you kept the receipts. That flexibility is why some people treat the HSA as a stealth retirement account, letting investment gains grow untouched for decades before pulling any money out.
Recordkeeping Is on You
Proving that a distribution matched a qualified expense is your job, not the custodian’s. If the IRS audits your return, you need provider invoices, explanation of benefits documents, and receipts showing what you paid. Without them, the IRS treats the withdrawal as non-qualified and assesses tax plus the penalty below. Your tax-free withdrawals cannot exceed your total unreimbursed qualified medical expenses.
When Withdrawals Cost You
Pulling money out for anything other than qualified medical expenses triggers two hits. The entire amount counts as ordinary income at your marginal rate, and if you’re under age 65, the IRS adds a 20% penalty on top.1Internal Revenue Service. Publication 969 (2025), Health Savings Accounts and Other Tax-Favored Health Plans
The math gets ugly fast. Someone in the 24% federal bracket who takes a $5,000 non-qualified distribution before 65 owes $1,200 in income tax and a $1,000 penalty, keeping only $2,800. Add state income tax and the effective cost of the withdrawal can easily exceed 50%.
The 20% penalty is waived if the account holder has reached age 65, become disabled, or died.5Internal Revenue Service. Instructions for Form 8889 (2025) Non-qualified distributions in those situations are still taxed as ordinary income, but the extra 20% goes away.
What Changes at Age 65
Once you turn 65, the 20% penalty disappears for good. Non-qualified withdrawals are taxed as ordinary income and nothing more. From that point on, the HSA effectively functions like a traditional IRA or 401(k) for non-medical spending, while medical withdrawals remain fully tax-free.1Internal Revenue Service. Publication 969 (2025), Health Savings Accounts and Other Tax-Favored Health Plans
Medicare is the wrinkle. Once you enroll in Medicare Part A or Part B, you can no longer contribute to an HSA. And when you enroll in Part A after 65, coverage is retroactive for up to six months. Any HSA contributions you made during that retroactive window become excess contributions subject to a 6% excise tax for each year they remain in the account.1Internal Revenue Service. Publication 969 (2025), Health Savings Accounts and Other Tax-Favored Health Plans Stopping contributions at least six months before enrolling avoids the problem. Selling investments and taking qualified distributions after Medicare enrollment stays tax-free; only new contributions are blocked.
Transactions That Can Disqualify the Entire Account
Some moves don’t just tax a single withdrawal. They destroy the account. If you engage in a prohibited transaction, the HSA ceases to be an HSA as of January 1 of that year. The full fair market value of all assets becomes taxable income, plus the 20% penalty if you’re under 65.1Internal Revenue Service. Publication 969 (2025), Health Savings Accounts and Other Tax-Favored Health Plans
Prohibited transactions include:
- Using HSA assets as collateral for a loan. The fair market value of the pledged assets is treated as a taxable distribution.
- Selling or leasing property between yourself and the HSA. You cannot sit on both sides of a transaction with your own HSA.
- Lending money to or from the HSA.
- Using HSA assets for personal benefit beyond paying qualified medical expenses.
Most custodians won’t facilitate the obvious versions of these, but the responsibility is yours. It’s worth knowing the boundary before you start treating the account like an ordinary brokerage.
Reporting Sales and Distributions on Your Tax Return
Because the sale itself is not a taxable event, there is nothing to report on your federal return from trading inside the account. Reporting only kicks in when you contribute or distribute. Your custodian sends two forms:
- Form 1099-SA reports total distributions during the tax year. The custodian reports the gross amount but does not decide how much is taxable.6Internal Revenue Service. Instructions for Forms 1099-SA and 5498-SA
- Form 5498-SA reports total contributions for the year and the fair market value of the account as of December 31.6Internal Revenue Service. Instructions for Forms 1099-SA and 5498-SA
You then complete Form 8889 with your Form 1040. That’s where you report total distributions, declare how much went to qualified medical expenses, and calculate any taxable amount and 20% additional tax. If non-qualified distributions are greater than zero, the 20% tax is computed on Form 8889 unless an exception applies (age 65, disability, or death). The result flows to Schedule 1 and Schedule 2 of your 1040.5Internal Revenue Service. Instructions for Form 8889 (2025)
The IRS does not verify your qualified expense claims in real time. But if reported qualified expenses look inconsistent with your income, coverage, or distribution patterns, an audit can follow. Keeping organized medical records is the only thing standing between a tax-free distribution and a surprise bill with a 20% surcharge.