If you are a foreign national in the United States—whether you are here lawfully or unlawfully—and you are married to a U.S. lawful permanent resident, you are, at the moment, NOT immediately eligible to obtain permanent residence (a green card). Only foreign nationals married to U.S. citizens are immediately eligible for permanent residence. However, you do have a possible path to U.S. residence, and your spouse can and should take steps to start the immigration process for you as soon as possible, if that's your goal (and if you eventually want U.S. citizenship).
As the spouse of a permanent resident, you are what's referred to as a "preference relative." Annual limits apply to the number of preference relatives who are allowed green cards each year. That means there can be years-long waiting lists for what's called a "visa number;" although in early 2021, there was no wait at all.
By filing a petition on Form I-130, issued by U.S. Citizenship and Immigration Services (USCIS), your spouse can put you on the visa waiting list and get you a "Priority Date" (the date USCIS accepted the I-130 for processing.) You'll track your progress based on that date, based on monthly announcements in the State Department's Visa Bulletin.
Even if the Visa Bulletin is showing that there's no wait in your category when you first apply, you will need to submit the Form I-130 to USCIS and wait for an approval before moving forward with the adjustment of status application; the law doesn't allow putting the whole packet together and doing a "concurrent filing" as is allowed for immediate relative spouses of U.S. citizens.
If the U.S. spouse becomes a citizen during the wait, the immigrant automatically converts to a so-called “immediate relative,” for which visas are immediately available.
It will not be legal for the immigrant to live in the United States while waiting for the priority date to become "current" unless the person happens to have a nonimmigrant visa or other status that makes the stay permissible. Also, there's an exception if you are the victim of battery or extreme cruelty by the U.S. spouse, and change your application to one filed on your own, under VAWA. Once you gain USCIS approval for an I-360 VAWA petition, your stay in the U.S. would convert to something called deferred action, and you would be eligible for a work permit.
In the ordinary case, however, you need to avoid a situation where your authorized stay expires before a marriage-based green card becomes available or you have at least put in an application to USCIS to adjust your status to that of a legal permanent resident. (Adjustment applicants are allowed to stay in the United States until USCIS makes a decision on granting a green card.) Not everyone is eligible to adjust status, and you can apply to adjust your status only at the time the U.S. immigration agencies allow you to.
Only certain people are eligible to adjust their status in the United States without having to go back home for an immigrant visa. (See Who Can Apply for a Green Card Through Adjustment of Status.) Unless you qualify under a special program (described below), all of the following need to be true:
Assuming you came to the United States lawfully and have been complying with the immigration laws, the important question is: Will your current legal status (student, temporary worker, visitor, or some other) really last until you're able to apply to adjust status?
To find out when your Priority Date has become "current" and you are thus eligible to apply to adjust status, you must check the State Department's Visa Bulletin, which is updated every month.
It contains a chart for “Family-Sponsored Preferences,” called “Dates for Filing Family-Sponsored Visa Applications.” Right above it is a paragraph telling you whether USCIS has determined whether you can use the dates in this chart. If the answer is yes, look at the date in the “F2A” row in the column for your country of origin. (If you don't see your country's name, you're in “All Chargeability Areas Except Those Listed.”) If your spouse filed the I-130 petition before this date, you can apply to adjust your status.
If USCIS has said that you cannot use the “Dates for Filing Family-Sponsored Visa Applications” chart that month, you must use the “Application Final Action Dates for Family-Sponsored Preference Cases” chart instead. You'll notice that the dates in this chart are earlier, so the wait is longer. The dates in this chart are also the dates the State Department uses to actually give out your immigrant visa, regardless of when you applied.
If your spouse becomes a U.S. citizen and your latest entry to the U.S. was lawful, you might be able to adjust status even if you have not been maintaining lawful status or you have worked illegally. (The usual rules allowing adjustment of status have exceptions for spouses of U.S. citizens who entered the U.S. with permission.)
There is some danger to the strategy of waiting for your spouse to become a U.S. citizen, however, if it means that you have to live in the United States beyond the period you were allowed to stay.
If you stay in the United States for six or more months beyond the expiration of your permitted stay and then leave the United States, you can be prevented from reentering the United States for three or ten years—even if you are otherwise entitled to a green card through marriage. (See Consequences of Unlawful Presence in the U.S.; Three- and Ten-Year Time Bars for further discussion.)
Also, you could be picked up and placed into removal (deportation) proceedings at any time. If you are deported after having lived in the United States illegally for more than year, you won't be able to come back for ten years, unless you get a waiver (see below).
If you are not eligible to adjust status, your application process will follow this sequence:
All or part of your waiting period can be spent in the United States, if you have the necessary legal status. (Of course, if you are able to spend all of your waiting period in the United States, you will probably want to adjust your status instead.) If you have to leave the United States, you can't come back just because you filed your application for an immigrant visa; you have to remain outside the United States until you get the immigrant visa from a U.S. consulate.
Although staying in the U.S. in unlawful status for more than 180 days while waiting for your application date could pose problems, you should not have a problem getting an immigrant visa to return if you stay illegally for any period of time less than that (unless you've done something, like commit a crime, that makes you inadmissible for some other reason). It still is not a great idea to stay illegally for any length of time, as it might affect future travel to the U.S. if you don't get the immigrant visa for some reason.
If you leave the United States after overstaying your visa by more than six months but less than one year, you likely will have to wait three years to come back with your immigrant visa. However, a good portion of that time is time you would have spent waiting for the visa to become available anyway. Likewise, if you leave the United States (or are deported) after you have overstayed your visa by more than one year, you likely will have to wait ten years to come back with your immigrant visa.
In some circumstances, USCIS will waive (forgive) your unlawful presence so that you are not subject to the three-year or ten-year ban on return to the United States. To get a waiver request approved, you will have to show that your not receiving a visa immediately will cause extreme hardship to your spouse in the United States, or if you happen to have a U.S. citizen or permanent resident parent in the U.S., to that person.
When the law says "extreme," it means much more than the sadness your family will feel at your being thousands of miles away. The classic case of extreme hardship is someone whose U.S. spouse or parent has severe medical or emotional problems that require your regular attention. Financial hardship will also be taken into account. If the waiver is approved, you could leave and apply for your green card at a U.S. consulate. For more information , see When Is a Waiver of Inadmissibility Available for a Green Card Applicant?
If USCIS approves the visa petition your spouse filed for you (on USCIS Form I-130), you (and your children) may be able to adjust status once your Priority Date becomes current even if your spouse dies before this happens.
This assumes, however, that you lived in the U.S. at the time of your spouse's death and continue to live lawfully in the United States. Check with an immigration attorney for details.
There are also provisions for allowing a substitute I-864 Affidavit of Support, given that your spouse can no longer submit one. Unlike with the situation of the spouse of a U.S. citizen, however, you cannot petition for yourself if your spouse never filed the petition.