When to book? For me as early as is convenient after I have my hotel and airline set. After all for travelers like me flexibility isnt a function of the train ticket, its the airline and the hotel. Then there is the concern that the train will sell out or maybe just the cheap tickets will sell out; and the number of seats to select from might be an issue. I am no expert on every rail line and I hate surprises.
On the route that I picked below there is a trian every hour so I wouldnt sweat it too much. Just may cost you more if you dont book in advance. Yes, backpackers staying in hostels is an exception to this thinking.
As for seats, I checked the next train out today for Vienna (mid afternoon) and about 15% of the seats were available. But I also checked among the most popular morning trains tomorrow (09:40) and the app would not let me select a seat so I imagine its pretty full.
For trying to find the right time to buy, I checked a popular train route. Budapest to Vienna on the MAV site https://jegy.mav.hu/ . I checked starting tomorrow and every day for over a month.
- This coming week, the non-refundable prices are between 30 and 40 euro second class for the two trains I checked (08:40 and 09:40).
- 30 days out they are between 15 and 20 euro on the trains I checked.
- First class drops from about 50 euro this coming week to 27 euro about a month out. That's real money.
I checked a bit further out and the savings was pretty minimal or not at all. The lowest i saw was 13 euro vs 17 euro after about a month. So for cost reasons I suspect 31 days is adequate. For seat selection options, I really don’t know; and wont guess. I also noted that the prices went up and down a few euro. That could be dynamic pricing in action or the day of the week. I didnt try and figure it out. If its dynamic pricing then booking earlier will be to your advantage.
I have no idea if this holds up with any other rail company.
I also looked briefly at the OBB website for the same train and for an equivlent train going in the other direction. Booking 30 days in advance can save you every bit of 30 euro a ticket. Of course, the MAV site at times is still cheaper.