Context. Ultraviolet photodesorption of molecules from icy interstellar grains can explain observations of cold gas in regions where thermal desorption is negligible. This non-thermal desorption mechanism should be especially important where UV fluxes are high. Aims. N 2 and O 2 are expected to play key roles in astrochemical reaction networks, both in the solid state and in the gas phase. Measurements of the wavelength-dependent photodesorption rates of these two infrared-inactive molecules provide astronomical and physical-chemical insights into the conditions required for their photodesorption. Methods. Tunable radiation from the DESIRS beamline at the SOLEIL synchrotron in the astrophysically relevant 7 to 13.6 eV range is used to irradiate pure N 2 and O 2 thin ice films. Photodesorption of molecules is monitored through quadrupole mass spectrometry. Absolute rates are calculated by using the well-calibrated CO photodesorption rates. Strategic N 2 and O 2 isotopolog mixtures are used to investigate the importance of dissociation upon irradiation. Results. N 2 photodesorption mainly occurs through excitation of the b 1 Π u state and subsequent desorption of surface molecules. The observed vibronic structure in the N 2 photodesorption spectrum, together with the absence of N 3 formation, supports that the photodesorption mechanism of N 2 is similar to CO, i.e., an indirect DIET (Desorption Induced by Electronic Transition) process without dissociation of the desorbing molecule. In contrast, O 2 photodesorption in the 7−13.6 eV range occurs through dissociation and presents no vibrational structure. Conclusions. Photodesorption rates of N 2 and O 2 integrated over the far-UV field from various star-forming environments are lower than for CO. Rates vary between 10 −3 and 10 −2 photodesorbed molecules per incoming photon.