Single and double photoionization spectra of formaldehyde have been measured at 40.81 and 48.37 eV photon energy and the spectrum of the doubly charged cation has been interpreted using high-level electronic structure calculations. The adiabatic double-ionization energy is determined as 31.7+/-0.25 eV and the vertical ionization energy is 33 eV. The five lowest excited electronic states are identified and located. The potential-energy surfaces of the accessible states explain the lack of stable H2CO2+ dications and the lack of vibrational structure. The experimental double-ionization spectrum can be decomposed into two distinct contributions, one from direct photoionization and the second from indirect double photoionization by an inner-valence shell Auger effect.