For US tax purposes, if you home in Mexico is your primary residence (this is subject to documentary proof on audit) for 2 out of the 5 past years (from date of sale) up to $500,000 in gain is not subject to taxes if you file a joint return, and $250,000 is tax free if you file as single. Any gain above those amounts are subject to taxes at capital gains rates. You can claim a credit for any Mexican capital gains taxes you paid on the sale against any US tax you pay as a result of the sale.
For Mexican taxes, to claim the unlimited exemption from taxes on the sale of your personal residence you first must have lived as your primary residence it for five years prior to the date of sale and be a Mexican citizen or hold an FM2 visa. You must also have documentary proof that it was your primary residence for that period of time. Such proof would include phone bills and utility bills; passports showing entry and exit dates from Mexico, etc. You cannot have two primary residences for either Mexican or US tax purposes.
You cannot get the exclusion from Mexican tax if you only hold an FM3, even though you have lived in your home full time for the 5 years. You must convince the Mexican Notary that your really did live in the property being sold as your primary residence for at least five years. The Notary makes the final decision whether to exempt you from taxes or not.
You should consult with a Mexican accountant, contadore (CPA) or tax abagado (attorney) if you wish to take advantage of the personal residence tax exemption to learn the steps required to qualify. Do not wait until the last minute when it is too late!
Therefore, it is possible to qualify for the gain exclusion on your US tax return though you may not qualify for Mexican tax purposes.
US and Mexico Taxes for Americans Living in Mexico. If you have a fideicomiso, Mexican corporation, a foreign bank account in Mexico, or live in Mexico this blog will have data you need about the required forms 5471, 3520, 3520A, FBAR 114, 926, 8865, 2555, 1116, etc., which you may have to file if you live and work in Mexico.