When you are in Donostia-San Sebastián and want to go to Madrid you can take either bus or train
BUS
Company: www.alsa.es
Address: You need to buy the ticket in advance in «in PASEO FEDERICO GARCIA LORCA 1» or online in: www.alsa.es
TRAIN
Company: www.renfe.com
Address: Estación del Norte. Paseo de Francia, 22. You buy the ticket at the train station