From Hanoi it is a 9-hour train journey to Sapa.
Vietnam Rail operates some of the cars, but other cars in the train are operated by private companies (Tulico, Ratraco, Victoria Hotels, and others). Some of these cars are significantly nicer than the standard cars. You may need to arrange with a travel agency to get tickets on these tourist cars, but any traveler can purchase tickets for the VNR cars at the Hanoi train station.
Cheaper tickets, especially in hard sleeper class, can be hard to come by at times, as tour companies and travel agents will snap up these to foist on their own customers (too frequently a promised soft sleeper berth will turn into a hard sleeper when it comes time to board). To avoid rip offs better go to the train station by yourself and get the ticket from the ticket office. This is the only way to make sure that you will get what you have paid for. Travel Agencies in Vietnam are known for their bad business practice. Another possibility is to ask for help at your hostel (if it's a good one).
Insider travel tip:
Although one cannot be assured of finding a place, it is often possible to arrive at the station a short while before boarding time, as there are usually young men hanging around trying to hawk unfilled berths at the last minute. The price of these tickets will fall dramatically as departure time draws near.
Prices vary according to both the type of seat purchased and the season during which you are traveling. The times around Vietnamese holidays are particularly expensive and tickets cannot be assumed available for same day travel, so book ahead if possible. Travelers are recommended to purchase a berth in a soft or hard sleeper car, though the trip in soft seat class is not intolerable (that's what we did and it was ok). For a bed, expect to pay in the area of 150,000-250,000 dong (one-way). There is usually a dining car serving good, surprisingly affordable noodles (8000 dong) and rice porridge (6000 dong), but it's always wise to bring your own snacks and drinks as well.
The train ends at Lao Cai. From there, dozens of shuttle buses will be waiting outside the station to take you the remaining distance to Sapa, usually at a 'fixed' rate of 25,000 dong. It's often possible to bargain down to 20,000 dong or lower, depending on demand. The ride is about an hour of beautiful views (if the weather is good, it may be an hour of fog at other times) more than 1000 meters up into the mountains.
You may want to book a return ticket when you buy your outward journey, as picking up tickets in Lao Cai is harder than in Hanoi. The staff do not speak as much English, and they possibly only sell tickets for travel on the same day so sleepers may already be sold out unless you go first thing in the morning. Pay attention to the time of your return train. Trains leaving Lao Cai around 7PM will arrive in Hanoi at 4AM. If you don't make prior arrangements to return at an early hour, you may find yourself sitting outside of your hostel, waiting for the desk to open.
Another possibility is to get a bus ride to Dien Bien Phu at the northern border to Laos. That's a complete day in the bus, riding through terrific landscapes!
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.Based on a work at Wikitravel.org & Traveldudes.org.