Renfe Intercity, Renfe and Renfe (12) will get you to Gibraltar at great prices. With over 1000 travel companies on Omio, you can find the best train times, prices and tickets for your trip.
Renfe Intercity is a high-speed train service operated by the Spanish national railway company, Renfe. It operates throughout Spain, connecting major cities and towns with frequent departures throughout the day. The Intercity service offers a variety of train types, including the Alvia and Talgo, all of which offer comfortable seating and modern amenities. Alvia and Talgo offer fast trains but not as fast the high-speed trains like AVE, offering more stops. Passengers can choose from a range of ticket types, including Economy, Business, and First Class. Onboard facilities include Wi-Fi, power outlets, and a selection of snacks and drinks. The most popular routes for Renfe Intercity include Madrid to Barcelona, Madrid to Seville, and Barcelona to Valencia.
Here are some other resources that might have the information you need