Airports in Spain and Portugal (and nearby)
Above you can see all of the airports in and near Spain that have commercial, passenger flights, both nationally and internationally.
The blue dots represent main airports with flights all around Europe, while the red dots show small airports with only a few flights, often only within Spain and in many cases only during high season.
The only airports to have flights outside of Europe (apart from the occasionally north African flight) are Madrid, Barcelona and Lisbon. At times in the past, both Valencia and Malaga have had flights to the United States, but they haven't proven successful.
Flying to Madrid and Central Spain
As you can see, the area around Madrid is a barren, largely airport-less land, with the minor airports of Valladolid and Zaragoza the nearest to the capital. If you can't get a flight to Madrid, you would be better off getting a flight to another airport that is connected to the capital by the AVE high-speed train, namely... Valencia, Barcelona, Seville and Malaga.
See also: Interactive Rail Map of Spain
Flying to Portugal, France and Morocco
Visiting Spain doesn't mean you have to fly to Spain, as you have such good connections to Portugal, France and Morocco. In particular, Faro in Portugal has good bus connections to Seville, there are good ferries from Tangiers in Morocco to Spain, and both Perpignan and Biarritz airports in France are well connected to northern Spain.
Fly to Seville if you can, as this is the nicest city in southern Spain. Malaga airport is well connected to other cities in the area: you can take a bus straight from the airport to Seville or Granada. Only stay in Malaga if you have a particular reason to visit Malaga.
Jerez (where sherry wine is from) is well connected to both Seville and Cadiz, while Granada is a vacation itself.
Which Airport for Barcelona?
If you're visiting Barcelona, fly to Barcelona airport. Sounds obvious, but Ryanair calls Girona and Reus Girona Barcelona and Reus Barcelona, despite the fact it will take you two hours to get to them from Barcelona.
Zaragoza is connected to both Madrid and Barcelona by high-speed train - good if you're doing a circuit, but otherwise stick to Barcelona flights.
Flights to San Sebastian, Bilbao and the North
Bilbao is your best bet here. There is a bus every hour from Bilbao airport to San Sebastian if you don't plan on staying in Bilbao.
There aren't many flights to San Sebastian, so fly to Bilbao or Biarritz and connect.
Galicia, Asturias and the North-West
All of the airports in the north-west are small, though Santiago has more and more flights these days, and your choice in airport will depend on where you're flying from or where you plan on going to in Spain. Don't rule out flying into Porto and taking the train up.