There is a piece of software called "Trassenpreise kalkulieren" that you can download from
this page on the DB website; but be aware that you do have to watch which route it sends you (it is possible to specify via a certain route).
I prefer to use it for very long or complex journeys and double check the results against the Eisenbahn Atlas; if it gets too confusing then split a long trip up into sections. You will also find the atlas handy to look up the short codes for locations (eg Hamburg Hbf is AH).
When you open it, click on "Preisauskunft" in the top left corner, type out your locations in "aus" (from) and "ziel" (to) and choose an option from the drop down menu under "produkt" or you won't get a result (it does not appear to matter which "produkt" you select). Also note that for any S Bahn mileage the "S-Bahn Strecken" box under the locations will need to be checked.