There are two principal approaches to achieve this effect, namely Subtractive, or the Etch Back process; and Additive, or the Lift Off process.
Subtractive, or the Etch Back process involves the coating of the entire surface, followed by the removal of select portions to form the desired pattern.
Some sort of physical masking agent is normally used in the pattern generating step, followed by the removal of portions without damaging anything else by means of an appropriate type of etching system.
In the Additive, or Lift Off process, the pattern generating step involving some form of physical masking agent is followed by the coating process resembling the use of a stencil.
The openings in the mask allow only the desired pattern to get applied onto the actual substrate. The excess that ends up on the mask top is removed when the mask is lifted off. This article discusses this Lift Off Thin Film Deposition process.