What insider trading is
First of all, it is important to note that there are two different meanings for insider trading. The first one is illegal and it reiterates to anyone who makes a trade on the stock market and profits (or avoids loss) based on information that that company was not public information at that time. The second one refers to a company officer trading company stock, which is not illegal unless they were using inside information to make a profit.
Perhaps the most famous example of insider trading in recent history is Martha Stewart. What exactly did she do wrong? Well, a company she invested in, ImClone, had a cancer drug that had been rejected by the FDA but that information was not available to the public at that time. The SEC believes that her friend Sam Waksal told her about this rejection and recommended selling her shares in ImClone immediately, which she did. By doing so, she avoids a huge loss when the stock price is historically dropped. That is a textbook case of insider trading, and she faced prison time for it.
Why it is illegal
The Securities and Exchange Commission sets and enforces rules to make the stock market as fair a place to trade as possible. They believe that when someone trades using information that is not well-known, it is not fair to the general public. A publicly-traded company is required to share its financial reports and any significant News with the world so that shareholders and potential shareholders can make informed decisions. After all, the company is owned by the shareholders and they deserve to know what is going on with their company.
How to avoid trouble
Probably the easiest way for you to get into trouble is if you work for a publicly-traded company and try to trade your company's stock for a profit based on information you heard around the office that has not been made public yet. Sharing or receiving this information from a friend at another company is just as bad. These situations are very tempting, and understandably so. It is hard to profit on a trade after the news has already hit the market. However, that is exactly why it is illegal, so you should try to avoid it. There are many gray areas on what is considered inside information, but if you are in doubt, do not trade your company's stock. There are thousands of other companies you can invest in.