Ultracold atoms in optical lattices provide a versatile tool with which to investigate fundamental properties of quantum many-body systems. In particular, the high degree of control of experimental parameters has allowed the study of many interesting phenomena, such as quantum phase transitions and quantum spin dynamics. Here we demonstrate how such control can be implemented at the most fundamental level of a single spin at a specific site of an optical lattice. Using a tightly focused laser beam together with a microwave field, we were able to flip the spin of individual atoms in a Mott insulator with sub-diffraction-limited resolution, well below the lattice spacing. The Mott insulator provided us with a large two-dimensional array of perfectly arranged atoms, in which we created arbitrary spin patterns by sequentially addressing selected lattice sites after freezing out the atom distribution. We directly monitored the tunnelling quantum dynamics of single atoms in the lattice prepared along a single line, and observed that our addressing scheme leaves the atoms in the motional ground state. The results should enable studies of entropy transport and the quantum dynamics of spin impurities, the implementation of novel cooling schemes, and the engineering of quantum many-body phases and various quantum information processing applications.