A lot of people make the mistake of thinking that only intact dogs or dogs that have not been spayed / neutered feel the desire to engage in sexual behaviors. Humping, mounting, and masturbation are normal sexual behaviors in dogs. This is why we see some dogs get so hard and horny in broad daylight. It is the high level of Hyperandrogenism that causes dogs to feel an incredibly powerful sex drive. In dogs which have not been through castration, Androgens is called Hyperandrogenism.
You can tell if your dog has too many of Androgens by examining its hair and skin around its tail and rump. This hormone can be found mostly in male dogs, but it has also been found in female ones at low extents. The adrenal glands, testes and ovaries in dogs create a hormone called Androgens.