Our knowledge of the structure of matter is largely based on X-ray diffraction studies of periodic structures and the successful transformation (inversion) of the diffraction patterns into real-space atomic maps. But the determination of non-periodic nanoscale structures by X-rays is much more difficult. Inversion of the measured diffuse X-ray intensity patterns suffers from the intrinsic loss of phase information1, 2, and direct imaging methods are limited in resolution by the available X-ray optics3. Here we demonstrate a versatile technique for imaging nanostructures, based on the use of resonantly tuned soft X-rays for scattering contrast and the direct Fourier inversion of a holographically formed interference pattern. Our implementation places the sample behind a lithographically manufactured mask with a micrometre-sized sample aperture and a nanometre-sized hole that defines a reference beam. As an example, we have used the resonant X-ray magnetic circular dichroism effect to image the random magnetic domain structure in a Co/Pt multilayer film with a spatial resolution of 50nm. Our technique, which is a form of Fourier transform holography, is transferable to a wide variety of specimens, appears scalable to diffraction-limited resolution, and is well suited for ultrafast single-shot imaging with coherent X-ray free-electron laser sources4.