Earlier drafts of this trip had a last night in Madrid before a nonstop flight home. The booked itinerary works differently: you fly Bilbao → Madrid → San Francisco on Iberia, all in one day, with Bilbao as the actual last stop on the ground. That's why Bilbao got the third night — it's doing the job a Madrid night used to do.
The connection window in Madrid is built for a transfer, not an excursion — there's no realistic time to leave the airport. Treat this page as the logistics for getting home, not a guide to a city you won't really see.
Bilbao airport is ~15 min from the city center. Arrange the taxi the evening of Aug 16 so it's not a scramble.
A quick domestic leg. Sleep if you can; this is the early, low-effort segment.
Domestic-to-international connections at Barajas can involve a terminal change and security/passport recheck — leave buffer, grab coffee or a quick bite near the gate rather than venturing further.
This is the flight to actually rest on. Land SFO 16:40 the same day — a remote workday from the air, office Tuesday.