One thing is the same regardless of which way you buy your tickets: tickets don't go on sale until from five to 20 days before departure, depending on the destination and class of train. So even if you choose to buy your tickets online two months in advance, the agency still won't be able to get your tickets until reservations open. Tickets on popular routes, such as between Beijing and Shanghai, can sell out quickly, especially around Chinese holidays. You also will need to know which class of seat you want: hard or soft seat, or hard or soft sleeper. Hard-seat tickets are the cheapest; soft sleeper the most expensive. If you are boarding a train en route, you will only be able to get hard-seat tickets; contact an attendant once on board to see it you can get an upgrade.
The cheapest tickets are those that you buy at the train station yourself. Major cities, such as Beijing, Shanghai, Xi'an and Guangzhou, have special ticket offices where foreign travelers can buy tickets, and clerks almost always will be able to speak some English. Stations in smaller cities might not have a foreigners ticket office; if they do, English might not be spoken. Know the approximate time you want to leave in military time and the class of seat you want--a good phrase book can be invaluable here. In cities with multiple train stations, such as Beijing, make sure which station the train will be departing from. Beijing reservations are computerized, so you can buy tickets from one station for a train that departs from another.
If you don't want to wait in line, consider paying someone to do it for you. Your hotel's travel desk or a nearby travel agency will get you tickets for a small fee, usually under $5 per ticket. This should be seriously considered if you are in smaller towns or on a tight schedule with many sights you want to see. While someone else is standing in line at the train station, you can be out seeing the sights.
Online agencies are convenient to use because the websites are in English. Train schedules and prices are easy to follow. You can book in advance but remember the online agency won't be able to get tickets until reservations open. If you are landing in Beijing from an international flight and need to leave two days later, it is one way to guarantee you will have a ticket. You will pay a stiff fee for this convenience, however. Fees start about $20 per ticket and go up from there. Tickets will be delivered to your hotel.