Although more expensive than buses, trains are undoubtedly the most comfortable way to travel overland in Vietnam. There is one major train line in Vietnam, the 1723-kilometer trunk between Hanoi and Ho Chi Minh City, on which the Reunification Express runs. HCMC to Hanoi is more than 30 hours, and overnight hops between major destinations are usually possible, if not entirely convenient. It’s a good way to see the countryside and meet upper-middle class locals, but unless you are traveling in a sleeper car it is no more comfortable than buses.
AC Soft or hard sleeper is recommended, and purchasing as early as possible is a good idea as popular berths and routes are often bought out by tour companies and travel agents well before the departure time (hence being told the train is sold out at a station ticket window or popular tour company office does not mean there are no tickets available–they’ve simply been bought by another reseller). Booking at the train station itself is generally the safest way, just prepare on a piece of paper the destination, date, time, no. of pax and class. However, unsold tickets can often be bought last minute from people hanging around at the station–a train is rarely sold out for real, as the railway company will add cars when demand is high. Commissions on these tickets will drop away as the departure time draws nearer.
Be cautious when using a travel agent to purchase your train tickets, since there is nothing printed on the ticket saying the class you are booked in. This results in a common scam with private travel agents where you will pay them to book a soft-sleeper ticket, they then book you a cheaper hard-sleeper ticket, and you don’t know you’ve been scammed until you board the train and your berths are in the lower class. By then with the train on the verge of departing it is too late to go back to the scamming agent to demand compensation.
In addition, there are shorter routes from Hanoi leading northwest and northeast, with international crossings into China. One of the most popular of the shorter routes is the overnight train from Hanoi to Lao Cai (with bus service from Lao Cai to the tourist destination of Sapa).
Always try to buy your tickets at least 3 days in advance, to avoid disappointment, especially during peak holiday season, during which you should try to book at least a week in advance.
A recommended site to book train tickets online: http://www.vietnamtraintravel.com