Santiago de Compostela is a long way from Madrid and it isn't easy to get there from Madrid. We'd suggest going via a different city, such as Leon, or taking a guided tour.
How to Include Santiago on Your Spain Itinerary
Santiago is 600km from Madrid. That's as far as Barcelona or the southern tip of Andalusia. And as the high-speed AVE train doesn't yet reach Santiago, journey times are longer than to pretty much anywhere else in Spain. If you have no interest in visiting anywhere else between Madrid and Santiago, your best option is to fly.
But if you want to avoid planes, you're going to want to break up your journey. However, as the crow flies, there aren't really any major sights, with only Leon and its fantastic tapas scene really worth stopping for. And even then, you'll only want to make the trip if you're driving, as trains are painfully slow between Leon and Santiago and buses are not much better.
Instead, your best bet is to extend your itinerary somewhat and either head west into Portugal and then north, or north to the Basque Country and then west. However, this adds considerable travel time to your journey, so only do this if there are sights you are interested in along these routes.
Getting around Galicia is difficult by public transport. So unless you're taking a car, we would suggest visiting Santiago and the surrounding region by guided tour.
Check out these Guided Tours of Northern Spain from Madrid for some suggestions.
Train and Bus
The train from Santiago de Compostela to Madrid takes about seven hours and costs under 50 euros, with beds from about 80 euros. There is also a night train.
There are regular buses throughout the day between Madrid and Santiago de Compostela. The journey takes eight hours and costs about 60 euros, which is more than the train! There are cheaper buses, but these take even longer.
Trains from Madrid to Santiago de Compostela depart from Chamartin train station. Buses from Madrid to Santiago de Compostela depart from Mendez Alvaro bus station.
This 600km journey takes about six hours, traveling mainly on the AP-6, A-6, AG-53 and AP-53 highways. Note that AP roads in Spain are toll roads.
Consider a stop in Salamanca or Leon to break up the long journey.