Transmission spectroscopy has so far detected atomic and molecular absorption in Jupiter-sized exoplanets, but intense efforts to measure molecular absorption in the atmospheres of smaller (Neptune-sized) planets during transits have revealed only featureless spectra1,2,3,4. From this it was concluded that the majority of small, warm planets evolve to sustain atmospheres with high mean molecular weights (little hydrogen), opaque clouds or scattering hazes, reducing our ability to observe the composition of these atmospheres1,2,3,4,5. Here we report observations of the transmission spectrum of the exoplanet HAT-P-11b (which has a radius about four times that of Earth) from the optical wavelength range to the infrared. We detected water vapour absorption at a wavelength of 1.4 micrometres. The amplitude of the water absorption (approximately 250 parts per million) indicates that the planetary atmosphere is predominantly clear down to an altitude corresponding to about 1 millibar, and sufficiently rich in hydrogen to have a large scale height (over which the atmospheric pressure varies by a factor of e). The spectrum is indicative of a planetary atmosphere in which the abundance of heavy elements is no greater than about 700 times the solar value. This is in good agreement with the core-accretion theory of planet formation, in which a gas giant planet acquires its atmosphere by accreting hydrogen-rich gas directly from the protoplanetary nebula onto a large rocky or icy core6.