It only works on substances that can be crystallized. An x-ray source is aimed at the crystal, and the diffraction pattern that is created as the x-rays strike the crystal are studied. In much the same way that you can infer the structure of an object by looking at its shadow, the diffraction pattern can be used to infer the structure of the crystal.
The technique requires good laboratory skills--without good crystals, good images will not be obtained. The process of re-creating a three-dimensional structure from the two-dimensional diffraction pattern can be mathematized, but still requires experience and artistry.
In the tables below, you can see a progression of crystals from simple to complex. In each case, the crystallographer inspects the crystallograph and infers the structure.
Sodium Chloride (Salt, NaCl)
Myoglobin (a protein)
|Watson and Crick posing with a three-dimensional model of the DNA molecule.|
The key, then, is to look at the two-dimensional crystallograph and figure out, partly by mathematical analysis and partly by visualization, what sort of three-dimensional structure could give rise to that crystallograph.
Links to contemporary crystallography sites:
University of Cambridge showcase of molecular structures determined through x-ray crystallography
Fourier Transforms, part of an online tutorial on interpreting two-dimensional figures. Note that the tutorial shows how a process that can be used to reconstruct a three-dimensional image from its two-dimensional shadow.