Magnetic materials are of interest in a wide range of nanotechnologies such as for data storage, memory, logic, and sensing applications. Today, there is a strong desire to manipulate magnetism at timescales below the picosecond. There is therefore a high motivation in studying ultrafast magnetism at the nanoscale. Resonant soft X-ray scattering and imaging are unique techniques that can combine nanometer spatial resolution and femtosecond time resolution in the study of magnetic materials. We performed X-ray scattering experiments at the X-ray free electron laser in Hamburg, the European XFEL to measure the demagnetization in different magnetic thin films. This thesis will first present the different ways X-rays are generated. I will in particular focus on synchrotron radiation and the recent the development of X-ray free electron lasers (XFEL). I will then introduce resonant soft X-ray measurements and show how resonant X-ray scattering and X-ray imaging are powerful tools to investigate magnetism. I will illustrate this with two experiments carried out at the European XFEL in Hamburg. In the first experiment we performed X-ray holography to image magnetic structures in nanodots. In the second experiment we performed resonant X-ray scattering on magnetic thin films with stripe domains to elucidate domain motions at the ultrafast timescales.