4Cosmic rays are the highest energy particles found in nature. Measurements of the mass composition of cosmic rays between 10 17 eV and 10 18 eV are essential to understand whether this energy range is dominated by Galactic or extragalactic sources. It has also been proposed that the astrophysical neutrino signal 1 comes from accelerators capable of producing cosmic rays of these energies 2 . Cosmic rays initiate cascades of secondary particles (air showers) in the atmosphere and their masses are inferred from measurements of the atmospheric depth of the shower maximum, X max 3 , or the composition of shower particles reaching the ground 4 .Current measurements 5 suffer from either low precision, and/or a low duty cycle. Radio detection of cosmic rays 6-8 is a rapidly developing technique 9 , suitable for determination of X max 10, 11 with a duty cycle of in principle nearly 100%. The radiation is generated by the separation of relativistic charged particles in the geomagnetic field and a negative charge excess in the shower front 6, 12 . Here we report radio measurements of X max with a mean precision of 16 g/cm 2 between 10 17 − 10 17.5 eV. Because of the high resolution in X max we can determine the mass spectrum and find a mixed composition, containing a light mass fraction of ∼ 80%. Unless the extragalactic component becomes significant already below 10 17.5 eV, our measurements indicate an additional Galactic component dominating at this energy range.Observations were made with the Low Frequency Array (LOFAR 13 ), a radio telescope consisting of thousands of crossed dipoles, with built-in air shower detection capability 14 . LOFAR records the radio signals from air showers continuously while running astronomical observations simultaneously. It comprises a scintillator array (LORA), that triggers the readout of buffers, stor-5 ing the full waveforms received by all antennas.We have selected air showers from the period June 2011 -January 2015 with radio pulses in at least 192 antennas. The total uptime was ∼150 days, limited by construction and commissioning of the telescope. Showers that occurred within an hour from lightning activity, or have a polarisation pattern that is indicative of influences from atmospheric electric fields are excluded from the sample 15 .Radio intensity patterns from air showers are asymmetric due to the interference between geomagnetic and charge excess radiation. They can be reproduced from first principles by summing the radio contributions of all electrons and positrons in the shower. We use the radio simulation code CoREAS 16 , a plug-in of CORSIKA 17 , which follows this approach.It has been shown that X max can be accurately reconstructed from densely sampled radio measurements 18 . We use a hybrid approach, simultaneously fitting the radio and particle data. The radio component is very sensitive to X max , while the particle component is used for the energy measurement.The fit contains four free parameters: the shower core position (x, y), and scaling factors for the partic...