Capital gains exemption

We are getting ready to sell our house, where we have lived for the past 18 years.  It is our primary and only residence.  We don't rent any of the property to anyone else.  We have also not claimed any capital gains exemptions in the past.

 

How do I take advantage of the Capital Gains exemption for a home sale?  Is this something that will be done at closing for the sale of my current residence and/or at the purchase of my new residence?  Or is the exemption only reclaimed at the end of the year when I file my income taxes?