I'd just go to Google Flights and see what's available. From my origin, there is usually not much difference in costs to Barcelona vs. Madrid, and in 2016 there was at least one non-stop a day to each city.
Tickets to London can be a good bit cheaper, but keep in mind these issues before planning to fly to a place you don't want to visit, then travel onward by train or plane:
- What you are describing is an unprotected connection. Neither airline has any responsibility to see that you get to your ultimate destination. All the risk is on you.
- You cannot predict when your flight to Europe will land or how long it will take you to get through the immigration process. I believe the usual advice is to allow at least four hours before the departure time of an onward flight departing from the same airport, but even that is no guarantee that you'll make the connection. I haven't done this, but it's my understanding that if you have checked baggage, you'll normally have to retrieve it and re-check it, which means going back through security.
- If you opt for an even longer layover to reduce the risk, your probably sleep-deprived/jetlagged self will likely have a very miserable X hours sitting around an airport, making no progress toward reaching your actual destination.
- If you miss the onward flight or train, that ticket will be worthless unless you have bought a pricey refundable/changeable ticket, and you'll have to buy a replacement, at what is probably the high, walk-up price.
- If the onward flight is part of a round-trip ticket (probably quite a bad idea) and you miss the outbound flight away from your landing point, the rest of the ticket will be canceled.
- If you opt to spend the first night at your European gateway to eliminate nearly all (but not 100% of) the risk of missing the onward flight/train, that will significantly delay your arrival at your true starting destination.
I'd want to see really substantial savings before considering anything other than a connecting flight to my true starting point. Substantial as in a net savings of several hundred dollars each way. And I'm quite sure that when they time came for the actual flight, I'd be regretting the decision to try it. Sort of like what happens when you buy a super-low-cost airline ticket that requires you to be a the airport at 4:30 AM--doesn't look so good when it comes time to set your alarm the night before.
Now, if you think it would be nice to spend some time in London at the beginning of this trip, that's a completely different story.
Whatever you do, if your trip includes destinations other than Barcelona, don't forget the option of a multi-city flight that takes you into Barcelona and out of a different city. Don't try to piece together two one-way transatlantic flights on legacy carriers.