Context. Detailed characterizations of exoplanets are clearly moving to the forefront of planetary science. Temperature is a key marker for understanding atmospheric physics and chemistry. Aims. We aim to retrieve temperatures of N 2 -O 2 dominated atmospheres from secondary eclipse spectroscopic observations of the thermal emission of Earth-like exoplanets orbiting G-, K-, and M-stars, using large-aperture future space telescopes. Methods. A line-by-line radiative transfer code was used to generate synthetic thermal infrared (TIR) observations. The atmospheric temperature is approximated by an expansion with the base vectors defined by a singular value decomposition of a matrix comprising representative profiles. A nonlinear least squares fitting was used to estimate the unknown expansion coefficients. Results. Analysis of the 4.3 µm and 15 µm CO 2 bands in the TIR spectra permits the inference of temperatures even for low signalto-noise ratios (S/N) of 5 at medium resolution. Deviations from the true temperature in the upper troposphere and lower-to-mid stratosphere are usually in the range of a few Kelvin, with larger deviations in the upper atmosphere and, less often, in the lower troposphere. Although the performance of the two bands is equivalent in most cases, the longwave TIR is more favorable than the shortwave due to increased star-planet contrast. A high spectral resolution, as provided by the James Webb Space Telescope (JWST) instruments, is important for retaining sensitivity to the upper atmosphere. Furthermore, the selection of an appropriate set of base functions is also key. Conclusions. Temperature in the mid-atmosphere, relevant for understanding habitability, can be suitably characterized by infrared emission spectroscopy with a resolution of at least 1000 (ideally ≈2500). Obtaining the necessary S/N will be challenging even for JWST, however, it could be feasible with future space missions, such as the Origins Space Telescope or the Large Interferometer for Exoplanets. In the meantime, a least squares fitting with an appropriate set of base functions is also applicable for other classes of planets.