Diffraction occurs when a wave encounters an object or an opening or edge. They tend to spread out. The extent to which they spread out depends on the relative size of the object or opening and the wavelength. The closer the wavelength is to the size of the gap or object, the more spreading out occurs.
The reason for the occurrence of diffraction can be deduced from Huygen's Principle.