I was recently reminded of a special deal on hotels that we discovered on our last trip to Spain. That was two years ago, so it may have changed, but it's worth looking into if the conditions are right for you.
You can only get this deal when you are already in Spain.
If you go to any Spanish travel agency, you can buy hotel vouchers for 50 Euro per room (expensive if you're on your own, but if you're traveling with more than one person, not bad), and the agency will book you into a hotel in whichever city you want. The deal is, you will be booked into a hotel with MUCH higher room rates, so it's ends up being quite a luxury experience.
We wanted to return to Madrid a day earlier than planned, to have a more relaxed time getting to the airport. We bought two vouchers (6 people, you know) and asked for a hotel convenient to the Metro to the airport. They booked us into a four star hotel right on top of Chamartin station, and we ended up getting a suite which was almost as big as our flat and had more bathrooms. We were able to return our rental car a day early, and the savings on that paid for the room, with change.
Instead of an early start and frantic drive from the south of Spain to Madrid to catch our late afternoon flight, we had a leisurely breakfast, checked out the Prado for a couple of hours and then grabbed the metro to the airport. Much more civilized.
This might work out as a good solution if you find yourself heading somewhere busy without any hostel accommodations. Get together with a couple of other people and you *might* be able to find something decent.