I am working under a TN visa and in the past weeks there have been some laid offs in my company, furthermore, if I am terminated then I want to know how many days can I remain legally in the USA before I have to go back to my home country.
You are considered to remain in status until 60 days after you leave your job, or until your I-94 expires, whichever is sooner. 8 CFR 214.1(l)(2) says:
An alien admitted or otherwise provided status in E-1, E-2, E-3, H-1B, H-1B1, L-1, O-1 or TN classification and his or her dependents shall not be considered to have failed to maintain nonimmigrant status solely on the basis of a cessation of the employment on which the alien's classification was based, for up to 60 consecutive days or until the end of the authorized validity period, whichever is shorter, once during each authorized validity period. DHS may eliminate or shorten this 60-day period as a matter of discretion. Unless otherwise authorized under 8 CFR 274a.12, the alien may not work during such a period.
If you want to stay longer, you can file I-539 during this 60-day period to apply for Change of Status to B2 visitor status.