What part of northern Spain--the Basque Country? You can also check Bilbao and even San Sebastian/Donostia, but I think it's unlikely you'd get close to the fare you'll find into Barcelona and Madrid. Maybe you will if you fly out of a small, high-cost US airport where even big-city destinations are expensive.
You can check rail schedules from Barcelona and Madrid on the Renfe website to see whether things look appreciably better from one of those cities. https://www.renfe.com/es/en. Use Barcelona (Todas) and Madrid (Todas) as your points of origin. Use San Sebastian/Donostia if that is your destination.
I'm seeing more train departures from Madrid than from Barcelona and more arrivals in San Sebastian than in Bilbao (though Bilbao is a larger city). There's not a good fast rail line between those two cities. One normally uses the frequent bus service.
It's tricky to fly into Barcelona or Madrid and take a train on to San Sebastian or Bilbao the same day. It's tough to confident about when you'll be in a position to step onto a train in downtown Barcelona or Madrid, so many would suggest that you not buy the train ticket until you're on the ground in Spain.