X-rays striking a crystal lattice scatter off atoms in different layers. Constructive interference occurs only when the path difference between waves reflected from adjacent layers equals a whole number of wavelengths.
Where d = layer spacing, θ = angle from surface, n = integer order. W.L. Bragg and his father won the 1915 Nobel Prize for this discovery.