system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: If insider trading is illegal, how are CEOs allowed to trade shares of their own companies?
gpt
Most executives are governed by rules regarding insider trading, which are set by the company through bylaws or individual agreements with the executives.  Normally, they state the times when you can and cannot trade in reference to when certain pieces of information are about to be released.  For example, you are probably not allowed to trade a certain amount of days before financial statements are about to be published publicly.

If they're caught violating these laws, they'll be fired from the company (most likely), and the SEC will likely have some words with them as well.

Edit: To clarify, the agreements restrict their trading, usually, before and after major company events.  Often times, executives will clear it with the Board of Directors for any large trading in their own company.  By being candid in their intent to trade, they're helping to cover themselves from being accused of insider trading.