There are two primary causes of ESD. The first is when two materials touch each other and then are separated, such as when you walk across the carpet and your feet first contact the carpet then are separated from it. This is called tribocharging, and it results in a gradual buildup of an electric charge. Then, when you touch something that is conductive, you feel the shock as the charge leaves your body.
Another cause of ESD is a process called electrostatic induction. This takes
place when an item with an electric charge is placed near another item. If the
second item is conductive—that is, it conducts electricity—and yet is
insulated—meaning that it has an insufficient contact with the ground to allow
it to discharge an electric charge—it will begin to build up a charge. Then, as
with tribocharging, when it does touch something that is conductive, there will
be a flow of electricity from it to the other item: a discharge of static
electricity.
While static electricity may seem to be harmless relative to other forms of
electrical current, the fact is that it can be extremely damaging to electrical
components and can cause fires or explosions when it is introduced to flammable
liquids or gases. This is true even of those ESD events that are so minor that
you don't even feel them.