We present a new approach to constrain galaxy physical parameters from the combined interpretation of stellar and nebular emission in wide ranges of observations. This approach relies on the Bayesian analysis of any type of galaxy spectral energy distribution using a comprehensive library of synthetic spectra assembled using state-of-the-art models of star formation and chemical enrichment histories, stellar population synthesis, nebular emission and attenuation by dust. We focus on the constraints set by five-band ugriz photometry and low- and medium-resolution spectroscopy at rest wavelengths λ= 3600–7400 Å on a few physical parameters of galaxies: the observer-frame absolute r-band stellar mass-to-light ratio, M*/Lr; the fraction of a current galaxy stellar mass formed during the last 2.5 Gyr, fSFH; the specific star formation rate, ψS; the gas-phase oxygen abundance, 12 + log(O/H); the total effective V-band absorption optical depth of the dust, ; and the fraction of this arising from dust in the ambient interstellar medium, μ. Since these parameters cannot be known a priori for any galaxy sample, we assess the accuracy to which they can be retrieved from observations by simulating ‘pseudo-observations’ using models with known parameters. Assuming that these models are good approximations of true galaxies, we find that the combined analysis of stellar and nebular emission in low-resolution [50 Å full width at half-maximum (FWHM)] galaxy spectra provides valuable constraints on all physical parameters. The typical uncertainties in high-quality spectra are about 0.13 dex for M*/Lr, 0.23 for fSFH, 0.24 dex for ψS, 0.28 for 12 + log(O/H), 0.64 for and 0.16 for μ. The uncertainties in 12 + log(O/H) and tighten by about 20 per cent for galaxies with detectable emission lines and by another 45 per cent when the spectral resolution is increased to 5 Å FWHM. At this spectral resolution, the analysis of the combined stellar and nebular emission in the high-quality spectra of 12 660 Sloan Digital Sky Survey (SDSS) star-forming galaxies using our approach yields likelihood distributions of M★, 12 + log(O/H), and ψS similar to those obtained in previous separate analyses of the stellar and nebular emission at the original (twice higher) SDSS spectral resolution. Meanwhile, rest-frame ugriz photometry provides competitive constraints on M*/Lr. We show that the constraints derived on galaxy physical parameters from these different types of observations depend sensitively on signal-to-noise ratio. Our approach can be extended to the analysis of any type of observation across the wavelength range covered by spectral evolution models.