  In the present work the chemical composition of niobium surface upon 200-400
{\deg}C baking similar to "medium-temperature baking" and "furnace baking" of
cavities is explored in-situ by synchrotron X-ray photoelectron spectroscopy
(XPS). Our findings imply that below the critical thickness of $Nb_2O_5$ layer
(about 1 nm) niobium starts to interact actively with surface impurities, such
as carbon and phosphorus. By studying the kinetics of the native oxide
reduction, the activation energy and the rate-constant relation have been
determined and used for the calculation of the oxygen-concentration depth
profiles. It has been established that the controlled diffusion of oxygen when
the native-oxide layer represents an oxygen source is realized at temperatures
200-300 {\deg}C, while at 400 {\deg}C the pentoxide is completely reduced and
the doping level is determined by an ambient oxygen partial pressure. Fluorine
(F to Nb atomic ratio is about 0.2) after the buffered chemical polishing was
found to be incorporated into the surface layer probed by XPS (about 4.6 nm),
and its concentration increased during the low-temperature baking (F/Nb up to
0.35 at 230 {\deg}C) and depleted at higher temperatures (F/Nb=0.11 at 400
{\deg}C). Thus, the influence of fluorine on the performance of mid-T baked,
mild-baked (120 {\deg}C/48 h) and nitrogen-doped cavities must be considered.
The possible role of fluorine in the educed $Nb^{+5}$ to $Nb^{+4}$ reaction
under the impact of an X-ray beam at room temperature and during the thermal
treatment is also discussed. The range of temperature and duration parameters
of the thermal treatment at which the niobium surface would not be contaminated
with impurities is determined for industrial applications.
