Long story short: If you drop your guard in combat, by doing something distracting, opponents can get a free attack on you. That's what an AoO is.
Figure out which squares you can attack with your current melee weapon, without moving; usually, that's the 8 squares adjacent to you. Those are called "threatened squares." You can take an AoO into any square you threaten.
When you're standing in someone else's threatened area, you will provoke an AoO if you take certain actions. Spellcasting is the most common, though there are a lot of others. The actions that provoke AoO are listed on
this SRD page, or in the Combat chapter of the DMG.
You can also draw an AoO by moving. Whenever you
leave a threatened square, your opponent gets the attack. However, this is where it gets complicated, because there are two exceptions to this rule.
First, if your
entire move for the round is a 5' step, the movement does not draw an AoO. (You can still draw an AoO by taking some other action.)
Second, if you do
nothing else but move during the round, the space you start in is not considered threatened. This means you can leave your starting space without drawing an AoO (but you may provoke one later, if you move through a different threatened space).
That's about as simple as it gets.
Other things to remember:
You can make only one AoO per round, unless you have the Combat Reflexes feat.
You can only make an AoO with a melee weapon. A bow, crossbow, or other missile weapon does not threaten any area, and cannot be used to make AoOs.