Common reasons
Many dogs hump when they are excited, such as when visitors arrive or during play. Some do it when they are unsure or overwhelmed. Puppies often do it as part of growing up.
What to do
Calmly interrupt it, ideally just before it starts, by calling your dog away or tossing a treat on the floor. Then ask for something they cannot do at the same time, like a sit, a hand touch or going to their mat. Telling them off can add to the excitement or stress behind it.
Lower the excitement
Notice when it tends to happen, and give your dog a break or a chew before things get too exciting. If it happens during play with another dog, take a short break so the other dog is not pestered.
When to see your vet
Constant humping, or a lot of licking or discomfort around the genitals or tail, can be a sign of a health problem such as an infection or itchiness. Book a vet check.