I assumed I would rent directly from one of the car rental companies at the airport.
You want to book before you leave.
Rates go up as you approach your actual travel dates.
Cars are one of the first things I prepay for, though there are options to pay later.
Start first with rentalcars.com and autoeurope.com. If you have Avis or other agency accounts, you can check those as well but you generally won't find lower rates.
Read the fine print about one-way fees. Typically not included in the rental.
See if you have premium credit card which will cover the deductible. But you have to decline CDW. However, in many countries you can't decline CDW so a card like Chase Sapphire REserve will be a secondary card.
I would discourage driving just after getting off a 10 hours or more international flight. I've done it but the warning is that it's like driving under the influence, after a long time ride, across multiple time zones.
Would be better to spend a night before trying to do much driving.
Unfortunate thing about Madrid is that you have to go into the city to take long train or bus trips.
Be wary of regional auto rental chains If it's a Spanish company, they may have reputation for claiming damage.
Check the car when you get it, go around look for clear signs of damage ahead of time. If you see something they didn't call out in the rental contract, point it out to them. Also take videos or photos if necessary.
Don't pay for extras like GPS. Instead you can save locations in Google Maps as Favorites and if you open Google Maps on your phone, while logged in with the same Google account, those saved Favorites will be easier to re-find.
You need data access though to stream Google Maps for longer trips. So you need a charger cable and a cigarette lighter to USB adapter if you plan to use navigation on your phone a lot. Also need some kind of way to mount it higher on the dash, typically there are clips that mount to the heating and AC vents on the car.
Other types of fees which may not be included in your rental contract include highway use fees and pick up and drop off fees for airports and train stations.
If you do rent from rentalcars.com or autoeurope.com, they have apps. to which you can download vouchers so you don't have to print them out if you don't want to.