First I flood my cookie with royal icing and let it dry completely.
I like to use royal icing that is the consistency of natural peanut butter.
I position my stencil where I want it on my cookie and then use nice long even strokes(with a palette knife) hopefully most going in the same direction and over the openings in the stencil. The only exception to this is with lettering, I usually have to go over it again in the opposite direction for complete coverage. Because this is rather thick icing, it also dries very fast so you have to be kind of quick. When you have covered every opening carefully lift your stencil straight up trying not to pull.
Once done they will dry very quick because you have used a thick icing.
Practice on parchment or waxed paper first to get the hang of it.