529 plans let you set aside money toward educational costs in accounts that generate tax-free income. As long as you use the money for qualifying expenses, then you'll never pay tax on the money. With generous contribution limits that in most states are well into six figures, these accounts offer a substantial amount of flexibility with no income-based restrictions on their use.
For example, if an investor in a 25% tax bracket had $10,000 in long-term capital gains, there would be a tax liability of $1,500. If the same investor sold underperforming investments carrying $10,000 in long-term capital losses, the losses would offset the gains, resulting in a tax liability of 0. If the same losing investment were brought back, then a minimum of 30 days would have to pass to avoid incurring a wash sale.