How do you avoid paying taxes? Is that a serious question? If you ever figure it out, let me know!!
Anyway - here is what the IRS says about capital gains:
Capital gains and losses are classified as long-term or short-term, depending on how long you hold the property before you sell it. If you hold it more than one year, your capital gain or loss is long-term. If you hold it one year or less, your capital gain or loss is short-term.
Net capital gain is the amount by which your net long-term capital gain is more than your net short-term capital loss.
The tax rates that apply to net capital gain are generally lower than the tax rates that apply to other income and are called the maximum capital gains rates. For 2007, the maximum capital gains rates are 5%, 15%, 25% or 28%.
If your capital losses exceed your capital gains, the excess is subtracted from other income on your tax return, up to an annual limit of $3,000 ($1,500 if you are married filing separately).