Non-thermal desorption from icy grains containing H$_2$CO has been invoked to explain the observed H$_2$CO gas phase abundances in ProtoPlanetary Disks (PPDs) and Photon Dominated Regions (PDRs). Photodesorption is thought to play a key role, however no absolute measurement of the photodesorption from H$_2$CO ices were performed up to now, so that a default value is used in the current astrophysical models. As photodesorption yields differ from one molecule to the other, it is crucial to experimentally investigate photodesorption from H$_2$CO ices. We measured absolute wavelength-resolved photodesorption yields from pure H$_2$CO ices, H$_2$CO on top of a CO ice (H$_2$CO/CO), and H$_2$CO mixed with CO ice (H$_2$CO:CO) irradiated in the Vacuum UltraViolet (VUV) range (7-13.6~eV). Photodesorption from a pure H$_2$CO ice releases H$_2$CO in the gas phase, but also fragments, such as CO and H$_2$. Energy-resolved photodesorption spectra, coupled with InfraRed (IR) and Temperature Programmed Desorption (TPD) diagnostics, showed the important role played by photodissociation and allowed to discuss photodesorption mechanisms. For the release of H$_2$CO in the gas phase, they include Desorption Induced by Electronic Transitions (DIET), indirect DIET through CO-induced desorption of H$_2$CO and photochemical desorption. We found that H$_2$CO photodesorbs with an average efficiency of $sim 4-10 times 10^{-4}$ molecule/photon, in various astrophysical environments. H$_2$CO and CO photodesorption yields and photodesorption mechanisms, involving photofragmentation of H$_2$CO, can be implemented in astrochemical codes. The effects of photodesorption on gas/solid abundances of H$_2$CO and all linked species from CO to Complex Organic Molecules (COMs), and on the H$_2$CO snowline location, are now on the verge of being unravelled.