Context. Determining distances to individual field stars is a necessary step towards mapping Galactic structure and determining spatial variations in the chemo-dynamical properties of stellar populations in the Milky Way. Aims. In order to provide stellar distance estimates for various spectroscopic surveys, we have developed a code that estimates distances to stars using measured spectroscopic and photometric quantities. We employ a Bayesian approach to build the probability distribution function over stellar evolutionary models given these data, delivering estimates of model parameters (including distances) for each star individually. Our method provides several alternative distance estimates for each star in the output, along with their associated uncertainties. This facilitates the use of our method even in the absence of some measurements. Methods. The code was first tested on simulations, successfully recovering input distances to mock stars with 1% bias. We found the uncertainties scale with the uncertainties in the adopted spectro-photometric parameters. The method-intrinsic random distance uncertainties for typical spectroscopic survey measurements amount to around 10% for dwarf stars and 20% for giants, and are most sensitive to the quality of log g measurements. Results. The code was then validated by comparing our distance estimates to parallax measurements from the H mission for nearby stars (<300 pc), to asteroseismic distances of CoRoT red giant stars, and to known distances of well-studied open and globular clusters. The photometric data of these reference samples cover both optical and infrared wavelengths. The spectroscopic parameters are also based on spectra taken at various wavelengths, with varying spectral coverage and resolution: the Sloan Digital Sky Survey programs SEGUE and APOGEE, as well as various ESO instruments. Conclusions. External comparisons confirm that our distances are subject to very small systematic biases with respect to the fundamental H scale (+0.4% for dwarfs, and +1.6% for giants). The typical random distance scatter is 18% for dwarfs, and 26% for giants. For the CoRoT-APOGEE sample, which spans Galactocentric distances of 4−14 kpc, the typical random distance scatter is 15% both for the nearby and farther data. Our distances are systematically larger than the CoRoT distances by about +9%, which can mostly be attributed to the different choice of priors. The comparison to known distances of star clusters from SEGUE and APOGEE has led to significant systematic differences for many cluster stars, but with opposite signs and substantial scatter. Finally, we tested our distances against those previously determined for a high-quality sample of giant stars from the RAVE survey, again finding a small systematic trend of +5% and an rms scatter of 30%. Efforts are underway to provide our code to the community by running it on a public server.