An illegal contract is unenforceable under the law for the simple reason that it is illegal. Most often, an illegal contract is deemed illegal because the contract is ultimately designed to perform some illegal function or purpose. For example, a “contract” under which one individual pays another to commit murder would be considered an illegal contract and would be entirely unenforceable.
An illegal contract thus must clearly and definitively be deemed illegal from one of the terms built into the contract in order to be considered unenforceable. A contract which might potentially lead to illegal action, but which does not immediately involve any such illegal action would ultimately be considered a legal contract.
For example, if a drug user were to purchase items which might potentially be used to create something for imbibing drugs, that contract might not be illegal, as the purchase of those items in and of themselves would still be considered legal and enforceable. If an individual made a contract to assist the drug user in setting up the device, however, that would likely be considered an illegal contract.
One of the most common types of illegal contracts are contracts which are in restraint of trade. This means that contracts which in some way prevent or control the manner in which an individual might perform trading would ultimately be deemed illegal and unenforceable, as only laws can restrict trading practices, not contracts. There may be some exceptions to this in certain instances, but for the most part, any such contracts would be deemed illegal.