This is a popular question I've been hearing lately. The immediate answer, of course, is that "it depends."
If we're talking about where you should be standing when the ball is at the other end of the field for a corner kick, the answer is that you should be somewhere outside of your 18 yard box, in a "sprinter's stance" (one foot in front of the other), ready to close ground to your last defender. Anything played over the top of that defender will be easier for you to deal with, since you will be running forward and can easily (we hope) clear the ball out of danger.
So, when the ball is at the other end, don't be stuck inside your 6 yard box!
As the ball moves near the midfield line, your exact distance from the goal line will depend on your ability to get back quickly in the event of a long shot; that, in turn, depends on the quality of the opponent, the size of the field, your individual speed and "drop step" ability. Most high level keepers will be just outside, or at the top of, the 18 yard box in these situations. When the attacking team gets closer to your line, you can move back into your 18 yard box, taking care to consider the same criteria.
Now, the most common question regarding how far off the line a keeper should be involves where to be positioned on a standard shot. Generally, for shots from roughly 25 yards out, you can stand very slightly in front of the goal line, and thus minimize chance of a ball looping in over your head. As shooters get closer, you can move further out, as this will "cut the angle" that the shooter has. For a shot from 18 yards out, most goalkeepers at the high school level can be 3 to 4 steps off the line, depending on height and ability to get back to the line for a chip. Younger goalkeepers need not be this far out, as the shooters will not have not the power that necessitates closing too far, and the lack of height creates vulnerability for a chip.
If you watch international games, you might see goalkeepers on top of the 6 in these situations where the ball is about 20 yards out. That is because they need to be this far out to "cut the angle" of shooters that have a lot of power on their shots; also, these keepers are very strong at executing a drop step and retreating to their lines.
So, don't think you need to do exactly what you see on television, but understand that your starting position is individual, and is based on the situation, your natural assets, and your footwork.