Driving in Madrid is best avoided, because parking is a nightmare and traffic is challenging, but many of the nation's highways radiate from Madrid, including the A6 (Segovia, Salamanca, Galicia); the A1 (Burgos and the Basque Country); the A2 (Guadalajara, Barcelona, France); the A3 (Cuenca, Valencia, the Mediterranean coast); the A4 (Aranjuez, La Mancha, Granada, Seville); the A42 (Toledo); and the A5 (Talavera de la Reina, Portugal). The city is surrounded by ring roads (M30, M40, and M50), from which most of these highways are easily picked up. There are also toll highways (marked R2, R3, R4, and R5) that bypass major highways, and the A41, a toll highway connecting Madrid and Toledo.
Blablacar is Spain's leading rideshare app in intercity travel with more global users than Uber. Its free platform allows you to book ahead using a credit card, and message with the driver to set meeting and drop-off points. Blablacar is the most affordable way to travel to Madrid's outlying cities and beyond as drivers aren't allowed to make a profit (you essentially help the driver offset the price of gas and tolls).