An "illegal immigrant" isn't a legal term, but usually refers to someone who either:
For purposes of this article, we will refer to an illegal immigrant as an undocumented immigrant.
It is possible to obtain a green card based on marriage to a U.S. citizen even if you have overstayed your visa. Your U.S. citizen spouse can file a Form I-130, Petition for an Alien Relative, on your behalf, together with your own green card application on Form I-485, Petition to Adjust Status. The latest versions of the forms, plus instructions, are available for free download on the Forms page of the USCIS website.
The filing fee (2019 figures) for a Form I-130 is $535 and for Form I-485 is $1,140 plus an $85 fee for taking your “biometrics” (mostly fingerprinting). (If you’re 79 or older, you don’t need to get or pay for biometrics.)
The fee for Form I-485 includes the initial application for a travel document ("advance parole"), which you can request by filing Form I-131, and for work authorization, which you can request by filing Form I-765.
However, if you have overstayed your visa, you should talk to an attorney before using your travel document to leave the U.S., since a record of unlawful presence has, in the past, been treated as a reason to bar your reentry. (The policy has become more lenient toward green card applicants with advance parole, but check in with an attorney just in case.)
All of this depends on your ability to prove that you entered the U.S. legally. You will need to show this in your application, by submitting a copy of either your visa stamp or your Form I-94 (Arrival/Departure record). If you entered the U.S. before April 2013, this white or green card would have been stamped by an agent when you entered the U.S. and would show the date you entered, in what status, and when your permitted stay will expire. If you arrived by air or sea after April 2013, you did not receive a paper I-94 and your arrival/departure record can instead be accessed on the Customs & Border Protection website.
You will also need to show that your marriage was entered into in good faith rather than to take advantage of U.S. immigration benefits. You can do so by providing evidence such as photographs, a marriage certificate, utility bills, bank statements, and a lease or insurance policies in your name as well as your U.S. citizen spouse’s name. If you have children together, submit copies of their birth records showing both your names listed as parents.
Once you complete your fingerprinting and interview with your spouse at your local U.S. Citizenship and Immigration Services (USCIS) office, you will likely be issued a two-year, conditional green card, and then be eligible to travel. These appointments will be scheduled by USCIS.
If you enter the U.S. as an undocumented entrant, you face an entirely different situation than the one described above. As a legal punishment for your unlawful entry, you will not be able to apply for a green card within the United States. Your U.S. citizen spouse can file Form I-130 only, as mentioned above, with USCIS. Once approved, that petition will be forwarded to the consulate located in or near your home country, where you will need to go for further processing.
However, a potential hurdle could arise after you arrive at the consulate. Once an undocumented entrant enters the U.S., stays for more than six months and then leaves, he or she triggers a three- or ten-year bar on reentry, as described in Consequences of Unlawful Presence in the U.S.—Three- and Ten-Year Time Bars.
If you are barred from reentry to the U.S., your only way to enter or be approved for a green card is likely to request a waiver of your reentry bar. There are two ways of doing this.
The first involves submitting a provisional waiver application to USCIS on Form I-601A before departing the United States for the consular interview at which the immigrant visa (in essence, a green card) can be granted. You will need to prove that, if denied the waiver and visa, your qualifying U.S. family members would suffer extreme hardship as a result. For details, see Am I Eligible for Provisional Waiver of Three- or Ten-Year Time Bar? and How to Apply for Provisional Waiver of Three- or Ten-Year Time Bar.
Applicants who aren't eligible to submit a provisional waiver application will need to be ready, after the consular interview in their home country, to file Form I-601, Application for Waiver of Grounds of Inadmissibility, with USCIS. You would most likely base the request on the extreme hardship that your U.S. citizen spouse or, if applicable, your U.S. citizen children would suffer if you were denied the green card (immigrant visa). If this waiver is denied, however, you would be barred from returning to the U.S. for either three years (if your period of unlawful presence in the U.S. was 180 days or more) or ten years (if your period of unlawful presence was one year or more).
In any case, as an undocumented entrant, you should consult an immigration attorney before your U.S. citizen spouse files any petition on your behalf or you leave the United States. This type of case can be extremely difficult.