What happens if you don’t use all the money in your 529 plan? This may happen for a variety of reasons: your child received a scholarship, chose a less expensive school than what you had budgeted for, or didn’t attend college after all. Maybe you had other family members contributing to the cost of college. Maybe you just put more money in than was needed. Is it lost? Fortunately, no. Unfortunately, though, you may need to pay taxes and/or penalties to withdraw the money. But you may not need to withdraw the money either.

The reason you didn’t spend the money will dictate whether there are penalties for a withdrawal. And the recipient of the withdrawal will determine the taxes.

First, though, should you withdraw funds that aren’t used? If you have another college-bound child, you can simply change the 529 account beneficiary to their name and use it tax- and penalty-free for their college expenses. Or you can hang onto the account in case your student attends graduate school, or make it available to the next generation if not. Assuming your grandchildren use the money for qualified educational expenses, it remains tax- and penalty-free. And after 25 or 30 years, even a small balance should grow substantially.

What if you do want to take the balance out, though? If your student got a scholarship or died or became disabled, then the withdrawal penalty is waived. In other cases, you’ll pay a 10% penalty on the earnings in the account.

Penalty or no, you’ll still pay income taxes on the earnings portion of the withdrawal, and may be subject to recapture of tax benefits you got for contributions. One way to mitigate the tax burden is to have the balance paid out to your college graduate so that it appears on their tax return, not yours. (Presumably a recent college graduate is in a lower income tax bracket than their parents.)

Earnings are the amount by which your account grew. Say, for example, that you contributed a total of $60,000 to a 529 account and it’s now worth $100,000. 60% of your account balance is contributions and 40% is earnings. Distributions are taken pro-rata from contributions and earnings, so any withdrawal will be 60% contributions and 40% earnings. In the above example, if you had $20,000 remaining in the account after your student completed college, $8,000 would be earnings subject to tax and penalty. (I chose these numbers for the easy math, not because they’re representative of anyone’s situation.)