If you're thinking of flying to London (or anywhere else in Europe) and then getting a separate flight on a separate ticket to Spain, be aware of all the potential pitfalls. Here's a good summary: https://www.tripadvisor.com/Travel-g41707-c207311/Newton:Massachusetts:Connecting.On.Separate.Tickets.html
And there's one complication that article doesn't mention. Almost all flights from the US to London land at Heathrow; many of the inexpensive flights onward from London to other European destinations use other London airports (counting Heathrow, London has six airports - as least as far as the airlines are concerned). You really need to allow a lot of time to change airports - or else build in a night in London between your flights.
On the other hand, there's nothing wrong with booking connecting flights all on one ticket; this is a true connection.
As to what you'll pay, there's simply no rhyme or reason any more. I just looked at some cities from New York in May 2017. Nonstop flights to Zurich were $369; nonstop flights to Geneva (usually similar price to Zurich) were about $1200, and even one stop flights were about $650 (and some had very long layovers, with total travel times of 30 hours). Why such disparity - who knows?
But, it's very common for cheaper fares to involve some inconvenience - long layovers, very early departures or late arrivals, geographic detours like Istanbul that lengthen the overall flight, etc. You have to decide how much "pain" you're willing to tolerate for a low airfare.
Look at Aer Lingus's website; they have flights from SFO to Dublin to Madrid, connecting in Dublin isn't too hard, and they often have very good fares without overly lengthy layovers.