I have a student visa in Spain, which will expire in a few months. I want to come back to the US for a few months and then return to Spain to continue my studies. Do I need to start all over, or can I extend my visa for another year? Is it a problem if I leave Spain for 2-3 months and then return?
You should consider what you would need to do if you were not planning to leave Spain. In that case, you would most likely need to get a residence permit (unless you already have one). If you already have a residence permit, it replaces your visa, and you can use it to travel out of Spain and back, as well as all over the Schengen area.
If you leave Spain, you will probably need a valid visa or residence permit to return. If you find yourself outside the Schengen area with no valid visa or residence permit, then you will probably need to apply for a new visa.
I say "probably" because I assume from "back to the US" that you are a US citizen. some Schengen countries allow US citizens to apply for residence permits without first obtaining a long-stay visa. If that is true in Spain, you might be able to enter as a visa-free visitor and then apply for a residence permit. But be certain of that before you attempt it.
The best course of action, if your circumstances qualify for it, is to apply for a residence permit before you leave Spain.