Photospheric (thermal) emission is inherent to the gamma-ray burst (GRB) ‘fireball’ model. We show here that inclusion of this component in the analysis of the GRB prompt emission phase naturally explains some of the prompt GRB spectra seen by the Fermi satellite over its entire energy band. The sub-MeV peak is explained as multicolour blackbody emission, and the high-energy tail, extending up to the GeV band, results from roughly similar contributions of synchrotron emission, synchrotron self-Compton and Comptonization of the thermal photons by energetic electrons originating after dissipation of the kinetic energy above the photosphere. We show how this analysis method results in a complete, self-consistent picture of the physical conditions at both emission sites of the thermal and non-thermal radiation. We study the connection between the thermal and non-thermal parts of the spectrum, and show how the values of the free model parameters are deduced from the data. We demonstrate our analysis method on GRB 090902B: we deduce a Lorentz factor in the range 920 ≤η≤ 1070, photospheric radius rph≃ 7.2–8.4 × 1011 cm and dissipation radius rγ≥ 3.5–4.1 × 1015 cm. By comparison to afterglow data, we deduce that a large fraction εd≈ 85–95 per cent of the kinetic energy is dissipated, and that a large fraction, ∼ equipartition of this energy, is carried by the electrons and the magnetic field. This high value of εd questions the ‘internal shock’ scenario as the main energy dissipation mechanism for this GRB.