Extreme states of matter, that is, matter at extremes of density (pressure) and temperature, can be created in the laboratory either statically or dynamically. In the former, the pressure–temperature state can be maintained for relatively long periods of time, but the sample volume is necessarily extremely small. When the extreme states are generated dynamically, the sample volumes can be larger, but the pressure–temperature conditions are maintained for only short periods of time (ps to μs). In either case, structural information can be obtained from the extreme states by the use of x-ray scattering techniques, but the x-ray beam must be extremely intense in order to obtain sufficient signal from the extremely-small or short-lived sample. In this article I describe the use of x-ray diffraction at synchrotrons and XFELs to investigate how crystal structures evolve as a function of density and temperature. After a brief historical introduction, I describe the developments made at the Synchrotron Radiation Source in the 1990s which enabled the almost routine determination of crystal structure at high pressures, while also revealing that the structural behaviour of materials was much more complex than previously believed. I will then describe how these techniques are used at the current generation of synchrotron and XFEL sources, and then discuss how they might develop further in the future at the next generation of x-ray lightsources.