For environmental problems such as global warming future costs must be balanced against present costs. This is traditionally done using an exponential function with a constant discount rate, which reduces the present value of future costs. The result is highly sensitive to the choice of discount rate and has generated a major controversy as to the urgency for immediate action. We study analytically several standard interest rate models from finance and compare their properties to empirical data. From historical time series for nominal interest rates and inflation covering 14 countries over hundreds of years, we find that extended periods of negative real interest rates are common, occurring in many epochs in all countries. This leads us to choose the Ornstein-Uhlenbeck model, in which real short run interest rates fluctuate stochastically and can become negative, even if they revert to a positive mean value. We solve the model in closed form and prove that the long-run discount rate is always less than the mean; indeed it can be zero or even negative, despite the fact that the mean short term interest rate is positive. We fit the parameters of the model to the data, and find that nine of the countries have positive long run discount rates while five have negative long-run discount rates. Even if one rejects the countries where hyperinflation has occurred, our results support the low discounting rate used in the Stern report over higher rates advocated by others.