Here are my recommendations.
1. Buy a car that has an excellent repair reputation. I.E. Honda, Toyota, or similar, and you won't even have to worry about extended warranties. I've only ever owned Hondas and Acuras. We have never purchased an extended warranty, and have never had any major repairs on any of our cars, ever. Our current cars are 7 years old and 4 years old, respectively. My 7 year old car is 4 years out of warranty, and I've not spent a dime on anything but scheduled maintenance (and new tires).
2. Use Edmunds.com to find what others in your area are paying for the car you are considering. Also, use their "real cost to own" tool, which takes into account insurance, gas, etc. over a 5 year period of time.
3. Get financing before you step foot in a dealership. On my last car purchase, I walked in with a blank check from my bank at 1.9% financing. The dealer beat it with 0.9% financing, so I went with the dealer. But, only go with the dealer financing if they can BEAT your other offer! The APR you are offered is ALL about your credit, so know what you "should" be able to obatin.
4. Don't impulse buy. Do your research, narrow it WAY down (down to make, model, color, extras). Then, find a dealer in your area that has THE car you want, and then go from there. Most dealers can get whatever car you want, but you might get a great deal if you are flexible on the color, at least.
5. Buy at the end of the month. Dealers usually have to turnover the cars in their lot as fast as possible, and as time goes on, they get desperate if they still have cars that have been sitting too long.
6. Do not add on a THING at the dealership. Not one little thing. No warranty, no "clear coat", no "scotch guard", etc. NOTHING. Take the car as is.
7. Insist that the car come equipped with floor mats, and don't settle for paying even one penny for them! I've negotiated in floor mats on every car I've purchased simply by telling the salesperson that they WILL be included in the price, and I will NOT pay for them. I've gotten cargo trays, wheel locks, and mud flaps as bonuses.

If they balk, walk out the door. I find that dealerships that charge for floor mats are the ones who will do their best to weasel every last penny out of you, because they assume you are a sucker.
My recommendation for a compact car under $20k is a Honda Fit. AMAZING little car! Great gas mileage (close to 45mpg hwy), cheap to fill up ($30 per fill up), excellent cargo space with numerous ways to fold up/down seats. Nice, comfy ride. We have the Sport version and got if for around $19500. Ours is 4 years old, has almost 75K miles on it, and going strong with not even one issue!