As a general rule, the ball must travel 10+ yards prior to the kicking team being able to recover the ball on a kickoff. This rule prevents the kicking team from merely tapping the ball a yard and ultimately picking the ball up without given a fair chance to the receiving team.
Any kick that goes out of bounds is flagged for illegal procedure. The receiving team automatically receives the ball at either the spot the ball went out or their own forty yard line.
If the receiving team touches the ball prior to the ball traveling 10 yards than an exception occurs. If this happens, the kicking team can recover the ball once a member of the receiving team touches the ball.
On top of the previously mentioned times an onside kick is unable to be recovered, kicks are made more difficult to recover due to some new rules that were recently introduced. Kicking teams may not: have a running start to recover the ball, have more or less than five players on each side of the kicker, and block the receiving team within 15 yards of the kick.
If you want to learn more about onside kicks and the rules of kickoffs, check out the following tutorials: