There are several car-payment calculators that will do the math for you (you'll find one here from About.com partner Cars.com). However, if you prefer to do the math manually, here's a relatively simple method.
First, figure out about what you can afford to pay per month. Multiply this figure by 36, 48 and 60 (for 3, 4 and 5 year loans).
To each of these figures, add what you can afford for a down payment. If you are trading in a car, visit a used car pricing site, such as Kelly Blue Book, to calculate the car's approximate value (use the trade-in value, which is the lowest figure and represents what you can probably expect the dealership to offer) and add that to your subtotal.
Finally, subtract 12 to 20% of the total for sales tax and finance charges. (This isn't totally accurate -- you'll be paying tax on the whole price, but finance charges only on the amount you actually finance -- but remember, we're estimating. If you live in a state without sales tax, subtract 7 to 10% just from the subtotal of your budgeted monthly payments.) That will give you a guideline as to how much you can afford to spend.
Monthly budget: $400 per month
Cash for down payment: $3,000
Trade-in value: $8,000
Subtotal: $25,400 (36 months), $30,200 (48 months), $35,000 (60 months)
Now subtract for taxes and finance charges -- we'll assume 8% tax and 7% financing, for a total of 15%. (Multiply each subtotal by .15, and subtract that amount from the subtotal.) That leaves us with $21,590, $25,670, and $29,750.
Considering that you will probably be able to negotiate off the sticker price, you should be looking at cars with an MSRP (sticker price) ranging from around $22,000 to $30,000.