The Lifshitz formula is derived by making use of the spectral summation method which is a mathematically rigorous simultaneous application of both the mode-by-mode summation technique and scattering formalism. The contributions to the Casimir energy of electromagnetic excitations of different types (surface modes, waveguide modes, and photonic modes) are clearly retraced. A correct transition to imaginary frequencies is accomplished with allowance for all the peculiarities of the frequency equations and pertinent scattering data in the complex ω plane, including, in particular, the cuts connecting the branch points and complex roots of the frequency equations (quasi-normal modes). The principal novelty of our approach is a special choice of appropriate passes in the contour integrals which are used for transition to imaginary frequencies. As a result, the long standing problem of cuts in the complex ω plane is solved completely. Some subtleties and vague points in previous derivations of the Lifshitz formula are elucidated. For completeness of the presentation, the necessary mathematical facts are also stated, namely, solution of the Maxwell equations for configurations under consideration, scattering formalism for parallel plane interfaces, determination of the frequency equation roots, and others.1 The electromagnetic field is coupled, through the Maxwell equations, with charges and currents, therefore one can take, as a dynamic variable, the local displacement of a continuous charged liquid that describes the free electrons inside the medium [28]. 2 In the general case, the spectrum of the differential operator may be more complicated [32]. However, in the Casimir calculations such problems do not occur. 3 In physical problems dealing with the plane boundaries, the surface modes and waveguide modes are called sometimes the guided modes [33].