You can buy it directly in Berlin Hauptbahnhof (Central Station) or buy it in advance through bahn.de it costs 39 euro each direction for adults over 26 years old.
This is perfect advice. I am planning to travel from Warsaw to Berlin in October. Last time I was in Berlin was 1988 and has changed a tad since then. Going to spend a day running around and back on the train heading west...
I also found the German interail page bahn.de very good too.