There are plenty of reasons why your rear shifting may have gone haywire, but one of the more common ones is that your bike is suffering from a bent derailleur hanger. I wouldn't think of this as it being "broken" per say, as the job of a replaceable derailleur hanger is to absorb abuse (bend or even snap if need be) so that your derailleur or frame are spared. The hangers are made to be weaker than the actual derailleur that attaches to them for this very reason. A bent hanger can happen quite easily, although a simple way to limit the chances of having to do this repair is to simply avoid laying your bike down or against anything on its driveside. I can't count how many times I've seen bikes bouncing up and down on their driveside as the shuttle truck makes its way up a rough road.
Before starting this repair it is important to note the differences in derailleur hanger types. The most common design is the simple bolt on hanger that is held in place by one or two bolts. If they do snap they are usually the most inexpensive type to replace. Some full suspension bikes (and a few hardtails) use a larger unit that encompasses both the dropout and derailleur hanger and bolts to the rear stays. This can make for a stiffer interface as the hanger is built into the dropout and may result in better shifting for that reason, especially when using the latest 10 speed gearing. The downside is that this piece is likely to be far more expensive than the simpler common bolt on hanger. The last type is the much less common non-replaceable hanger. While it can make for precise shifting, the consequences are high if you manage to severely damage it. This type is far less common and I'd recommend taking it to a professional shop to have it straightened if you manage to bend yours. Regardless of the type of hanger that your bike has, they all use the same technique to straighten and I can't stress enough that you need to be gentle and take your time throughout the repair. Spending an extra ten minutes doing this job may end up saving you money and downtime. Like a lot of repairs, this one requires special tools and if you don't have them, or don't feel comfortable doing the work, take the bike to your local shop to have them do the work.
Tools needed: Hanger Alignment Gauge, 5 mm allen key