Context. The evolution of intermediate and low-mass stars on the asymptotic giant branch is dominated by their strong dust-driven winds. More massive stars evolve into red supergiants with a similar envelope structure and strong wind. These stellar winds are a prime source for the chemical enrichment of the interstellar medium. Aims. We aim to (1) set up simple and general analytical expressions to estimate mass-loss rates of evolved stars, and (2) from those calculate estimates for the mass-loss rates of the asymptotic giant branch, red supergiant, and yellow hypergiant stars in our galactic sample. Methods. The rotationally excited lines of carbon monoxide (CO) are a classic and very robust diagnostic in the study of circumstellar envelopes. When sampling different layers of the circumstellar envelope, observations of these molecular lines lead to detailed profiles of kinetic temperature, expansion velocity, and density. A state-of-the-art, nonlocal thermal equilibrium, and co-moving frame radiative transfer code that predicts CO line intensities in the circumstellar envelopes of late-type stars is used in deriving relations between stellar and molecular-line parameters, on the one hand, and mass-loss rate, on the other. These expressions are applied to our extensive CO data set to estimate the mass-loss rates of 47 sample stars. Results. We present analytical expressions for estimating the mass-loss rates of evolved stellar objects for 8 rotational transitions of the CO molecule and thencompare our results to those of previous studies. Our expressions account for line saturation and resolving of the envelope, thereby allowing accurate determination of very high mass-loss rates. We argue that, for estimates based on a single rotational line, the CO(2-1) transition provides the most reliable mass-loss rate. The mass-loss rates calculated for the asympotic giant branch stars range from 4 × 10 −8 M yr −1 up to 8 × 10 −5 M yr −1 . For red supergiants they reach values between 2 × 10 −7 M yr −1 and 3 × 10 −4 M yr −1 . The estimates for the set of CO transitions allow time variability to be identified in the mass-loss rate. Possible mass-loss-rate variability is traced for 7 of the sample stars. We find a clear relation between the pulsation periods of the asympotic giant branch stars and their derived mass-loss rates, with a levelling off at ∼3 × 10 −5 M yr −1 for periods exceeding 850 days. Conclusions.