Insider trading is a form of securities fraud and is defined by the United States Securities and Exchange Commission (SEC) as the buying or selling of a publicly traded company's stock by someone who has access to material nonpublic information about the stock. The purpose of this unlawful conduct is to gain an unfair advantage over other investors who don't have access to the material nonpublic information and to unfairly manipulate stock prices. Insider trading can be either illegal and result in criminal penalties or lawful when it complies with the insider trading regulations of the SEC.

Insiders are defined as individuals who have access to material nonpublic information through their role in a company, such as employees and officers, or who are associated with the company, such as major shareholders. When insiders trade in a company’s stock, other investors do not know about the trades which can give the insider an unfair advantage.

Insider trading is illegal when those trading have access to material nonpublic information that other market participants do not. This type of insider trading violates federal securities law and can result in criminal penalties, including fines and jail time. The SEC has criminal enforcement powers to investigate and prosecute suspected violators of insider trading regulations.

In addition, the SEC can also bring civil charges against insiders who break the law. Civil penalties may include disgorgement (return of profits) and civil monetary penalties. Moreover, any gains made as a result of illegal insider trading can be flushed down and forfeit to the government.

When the trading of a company’s stock is done lawfully and conforms to the rules set forth by the SEC, it is considered legal insider trading. This generally occurs when an individual without access to material information about the company purchases stock. Legal insider trading is conducted in accordance with the SEC's guidelines, which require that corporate insiders file Forms 3 and 4 when trading their company’s stock. These forms are intended to ensure that investors are informed of any insider trading activities and that insider trading is monitored by the SEC.

In conclusion, insider trading has severe legal and financial consequences for those who practice it unlawfully. While there is no way to completely eliminate insider trading, establishing a strong corporate compliance program and adhering to the rules and regulations established by the SEC are essential steps in curbing insider trading and other forms of securities fraud.