They might be man's best friend and loyal to their pooch pals, but dogs do not go out of their way to be kind to a stranger.

Research published in Scientific Reports has shown that dogs will give food to others – providing they know the other dog.

"Prosocial behaviour" is any action intended to help someone else, such as sharing, giving and cooperating.

It has already been demonstrated in primates and studied experimentally in rats and jackdaws.

To study the behaviour, researchers trained "donor dogs" to pull a string, which would bring forward a tray. Paired with either a familiar dog that they lived with, or a non-threatening stranger dog of the same sex, the donors could choose to either give their partner an empty tray or a tray containing a treat.

When paired with a familiar dog, the donors gave food twice as often than when paired with a stranger.

"We weren't surprised that they gave to their familiar partners, but we were surprised by how little they gave to the strangers,” says co-author Rachel Dale of the University of Veterinary Medicine in Vienna, Austria.

While there has been research into prosocial behaviour between dogs and humans in the past, Dale says the results were mixed. It was impossible to tell whether the dogs were showing true prosocial behaviour or simply being obedient. 

"It is difficult because they are so primed to training and taking cues from humans," Dale says. "We need to be so careful."

Before you get too disappointed in Fido giving strangers the cold shoulder, there could be a good reason for the behaviour.

"In terms of group identification it makes sense," Dale says.

In order to cooperate with others, you need to have the tolerance to share with them: for example, when packs hunt large prey they need to share the kill.

Dale is currently running a similar study with a wolf pack. She hopes it will shed further light on whether dogs' prosocial behaviour is down to domestication or their wild roots.

You can follow Kara Segedin and BBC Earth on Twitter.

Like BBC Earth on Facebook and follow us on Instagram.