There are actually two distinct types of stye. Both are usually caused by a bacterium known as staphylococcus, or "staph" for short. It's a common bacterium on your skin that can over-reproduce and start infections.
When it causes the type of ordinary stye called an external hordeolum, it begins by infecting an eyelash at the root (the follicle), unleashing a process that results in swelling. This kind of stye can also start from a staph infection in an area close to the follicles called the glands of Moll and Zeiss. When the stye swells and begins to infect or clog other glands around the eyelid, it causes pain and discomfort. At this point, you may often see and feel a nodule, a small pimple-like reddish abscess that begins to fill with pus.
Not all styes are visible. A stye that forms beneath the surface of the eyelid will hurt, but it may never develop an external nodule. Styes form most commonly in the upper eyelid near the eyelashes, but can develop on the lower eyelid as well. Usually, only a small area of the eyelid swells, but the entire lid may occasionally become inflamed.
The second kind of stye, the internal hordeolum, is a more serious form of staph infection. It originates in a gland called the meibomian beneath the surface of the middle of the eyelid. Because it's buried in the central part of the eyelid, an internal hordeolum is more painful than the external kind. While the pus in an external stye will usually drain on its own, an internal one won't. The person will most likely have to visit a doctor to have it opened and drained.
Both external and internal styes are not contagious, and are never a sign of cancer.