I took nice modern double decker train from Prague to Karlstejn. The trip took about 40 min and the price was approximately 2 euros. When you get off the train it is quite clear where to go to castle – signs show it. it is 1,5 kilometers from the train station.
The best way to go to Karstajn from Prague is to take train on Hlavni Nadraži. The ticket costs 46 CZK, and it takes 43 minutes to get to Karlstejn. First train goes from Hlavni at 08.26. It runs every hour till 12.26. Then it starts to go every half an hour (12.56, 13.26, 13.56...). From 19.26 it again starts to go on full hour (19.26). Last train on Hlavni for Karlstajn you can catch at 00.26.
It is very nice to take this trip, you will enjoy landscape. Also ou will have a bit longer walk to reach the castle, but it is not any kind of problem, quite nice walk!
Trains leave roughly every hour from Prague's Smichov Station (in the southwest corner of the city, part of the subway system). Often the trains are called by their terminating station, and the one to Karlstejn usually finishes its run in Beroun, so listen for the "Beroun" train on the platform. When in Karlstejn listening for the return train, the Czech stationmasters call out "Praha-Smichov" which sounds like "Pra-Smichov." This will be your return train, which usually arrives and departs on-time.