U.S. synonym guides focus on legal/illegal and lawful/unlawful in their statutory sense as descriptions of what is permissible or impermissible according to a code of laws. The result, unfortunately, is not very satisfactory coverage of the terms as they are more broadly used in the real world.
For example, S.I. Hayakawa, Modern Guide to Synonyms and Related Words (1968) has this entry for lawful and legal (which it considers as part of a bundle of related words that also includes constitutional, legitimate, and licit):
Lawful implies conformity with laws, statutes, canons, precepts, principles, rules, etc. intended to regulate the conduct of those coming within their particular field of action. Thus one speaks of lawful debts, a lawful claim, a lawful marriage, of conducting a lawful business or making a lawful decision. Legal has nearly the same meaning, but is restricted chiefly to statute laws as they apply at certain times and places {Divorce is lawful but subject to various legal requirements before taking final effect; The legal speed limit within the town is 15 miles per hour.} ... Antonyms: illegal, ... unlawful.
And Merriam-Webster's Dictionary of Synonyms (1984) has this for unlawful and illegal:
unlawful, illegal, illegitimate, illicit are comparable when they mean contrary to, prohibited by, or not in accordance with law or the law. Otherwise than this negation in character, the words in general carry the same differences in implications and connotations as the affirmative adjectives discriminated at LAWFUL.
and this for lawful and legal:
lawful, legal, legitimate, licit mean permitted, sanctioned, or recognized by law or the law. Lawful differs from the others in implying a reference to various sorts of law (as divine law, natural law, or the law of the land, or as civil law, common law, or canon law). Consequently, the term often comes close in meaning to allowable or permissible {all things are lawful unto me,but all things are not expedient—1 Cor[inthians] 6:12} {tell me, which knave is lawful game, which not? Must great offenders, once escaped the Crown, like royal harts, be never more run down?—Pope} or sometimes to rightful or proper {the lawful heir} {a lawful prize} {the lawful sovereign} {that man was not Hannah's lawful husband—Ingamells} {William desired to reign not as a conqueror but as a lawful king—J. R. Green} Legal implies a reference to the law as it appears on the statute books or is administered in the courts; thus, the lawful heir is also the legal heir; the lawful owner of a piece of property is one whose legal right to to it is certain; a moneylender is entitled only to legal interest on his loans. Legal is used more often in the sense of sanctioned by law or in conformity with the law, or not contrary to the law, than in the sense of allowable by the terms of the law {a legal marriage} {the legal period for the payment of a debt} {the capture of the neutral ship carrying contraband was held to be legal} {she became the virtual head of our family, supplanting ... my Uncle Tiberius (the legal head)—Graves {the Vichy regime he considers an illegitimate, although, at first at least, it was outwardly legal—Guerard}
All of this may be accurate as applied to criminal and civil codes of law, but, as tankadillo points out in a rather underappreciated answer posted here ten years ago, use of illegal to refer to conduct outside the world of actual laws is extremely common, at least in the United States. In particular, multiple sports use the term illegal, not unlawful, to refer to various infractions of the rules. Thus, in U.S. football, penalties may be assessed for "illegal use of hands," an "illegal forward pass," an "illegal shift," an "illegal formation," or (more broadly) "illegal procedure"; in U.S. basketball (as in U.S. football), a referee may call a foul for "illegal defense" or an "illegal timeout"; and in U.S. baseball, a pitcher or batter may be penalized for applying an "illegal substance" to the ball or bat. In none of these cases would the word "unlawful" ever be used in place of "illegal" because in none of these cases is the infraction against any law; each simply involves violating the rules of the game.
Similarly (as tankadillo notes) a computer operating system may inform the user that "This program has performed an illegal operation and will be shut down." Essentially the operating system didn't understand or didn't approve of the program's behavior, so it closed the program. Likewise, none other than the Oxford Dictionary of Computing, sixth edition (2008) includes entries for "illegal character" and "illegal instruction":
illegal character Any character not in the character set of a given machine or not allowed by a given programming language or protocol.
illegal instruction An instruction that has an invalid operating code. It is sometimes deliberately inserted in an instruction stream when debugging in order to have a program halt, or interrupt, at a particular point.
Again, "unlawful character" and "unlawful instruction" are not in the lexicon because they aren't in real-world use.
In all of these areas, U.S. usage is exactly the opposite of what one might expect from the OED usage note cited in apaderno's answer: whereas the OED indicates that illegal narrowly implies "against formal statutory law" and lawful more broadly implies "contravening applicable rules," lay/informal U.S. usage treats unlawful as more strictly concerned with actual law (of some kind) and illegal as more broadly concerned with the normal and approved rules of play or operation.