Sure you can do it. If you are married you can profit up to $500k and there is zero federal tax on the profit if you have owned the property a minimum of 2 years, and it is your primary residence. If you aren’t married the exemption is $250k. Just to clarify further regarding what @Judi wrote, only the profit amount matters. If you bought the house for $200k and you sell for $240k, your profit is $40k and the $40k is what the IRS would be concerned with. If the house was purchased for $700k and you sell for $740k, again, the IRS only looks at the $40k. In both cases if you lived in the house as your primary residence the $40k would not be taxed, because it’s lower than the $250, $500k exemptions no matter what your marital status is.
There will be more than one person, especially over the age of 40, who might tell you you can only sell one time in your life and get the tax exemption, but that is absolutely false. It was changed many years ago. You can do it every two years for the rest of your life; until they change the law again. If you have not been living there as your primary residence the tax law is a little tricky. If that is your case let us know and I can explain some basics on the taxes and exemptions.
If your state has homestead exemptions that carry forward there might done rules regarding that on how fast you need to purchase to directly carry the homestead exemption.