To come up with total water needed, you have to work backwards from the end of the boil.
An example: If you want 5.5 gallons (to cover losses in transfer) and you boil for 90 minutes at 1 gal/hr boil off rate, you need about 7 gal at the beginning of the boil. To get 7 gallons of run off, you will need 7 gallons plus roughly a gallon for every 8 pounds of grain (to cover what the grain will absorb and not release). Suppose you have 12 pounds of grain - you are now up to 8.5 gallons of water. Add to this a little to cover water that is lost in equipment like hoses and under the false bottom or manifold of the mash tun, and make it 9 gallons.
So what do you do with all of this water? Your mash should have somewhere between 1 and 1.5 quarts of water in your mash for every pound of grain (many people use 1.25). For the example above, this would be 15 quarts (or 3.75 gal). After you add this to the mash tun with your grain, you will have 5.25 gallons of water left - this is your sparge water. As mentioned in another post, you can add this continuously as you drain (fly sparge) or in batches (surprisingly enough called batch sparging). Most people that batch sparge add this in two batches, so you would drain the mash (recirculate the first runnings until they run clear - no particles), add batch 1 (half of 5.25 gallons), stir, recirculate until clear, drain, then repeat for the last half of the sparge water.