Painful stimuli are picked up by specialised receptors known as nociceptors (nociception is the name given to the response of the nervous system to painful stimuli). When the nociceptors detect a painful (nociceptive) stimulus they send a message via the spinal cord to the brain.
The gate theory is based around the concept of balance between information travelling through two different types of nerve fibres:

Small nerve fibres that carry nociceptive information.

Large nerve fibres that carry non-nociceptive sensory information.

Simply put, if the amount of information being carried by small nerve fibres is greater than that carried by large nerve fibres then pain is experienced.
The pain gate is situated within the spinal cord and relies on two further types of nerve fibres:

Projection interneurones.

These are activated by information coming from the small nerve fibres.

Inhibitory interneurones

These are activated by information coming from the large nerve fibres.
Inhibitory interneurones will also remain active when the large fibres are dormant.

The pain gate operates in one of three ways:

1. Without any stimulation both the small and large fibres are quiet and the inhibitory interneurone is active, blocking the projection interneurone.

The gate is closed and the person experiences no pain.

2. With non-painful stimulation the large nerve fibres activate the inhibitory interneurone that blocks any minor painful stimulation ascending through the projection interneurone.

The gate remains closed and the person experiences no pain.

3. With painful stimulation the small fibres activate the projection interneurone that in turn blocks the inhibitory interneurone.

The gate is open and the person experiences pain.

If the amount of information travelling through the large nerve fibres can be increased we can effectively close the gate and reduce the amount of pain a person experiences.