When do I realize a capital gain on the sale of my home, and how do I calculate the gain?

Please refer to IRS Publication 523 Selling Your Home.