Just agreeing that I've never had problems with taxis in Spain (more than I can say for some countries). They use the meter, and while there are all kinds of legitimate supplements (such as for picking up at a train station, putting things in the trunk, or carrying more than a certain number of passengers), these are always posted clearly on a sign in the taxi.
In central areas of Barcelona and Madrid, taxis are everywhere. For an early morning flight, you may want to pre-book one; for anything else, just hail one in the street. And I'm sure that any time flights are arriving at the airports, there will be taxis waiting.
I also agree with Enric: what time is your flight arrival? There's nothing wrong with taking a taxi (particularly if you're arriving jet-lagged from the US), but it's quite possible the airport bus will be running. It looks like the last one leaves the airport about 1 AM (exact time depends on your arrival terminal).