By train

Trains from Madrid and Barcelona to Zaragoza (Delicias Train Station)

There are train connections to Zaragoza from Barcelona and Madrid train stations. You can travel from both cities to Zaragoza in less than two hours.

The cheapest tariff is Tourist-4M only if 4 people are travelling together. Then it comes P (Promo) and P+ (Promo plus). The former is cheaper because changes and cancellations are not allowed, which you can do if you buy a P+

Additional information on schedules and prices from Renfe website