Why are dogs so loyal to humans?
Dogs (wolves) are social animals, accustomed to living in packs. They grow up with a sense of obedience to a leader. If they oppose or become powerless, they are removed from the herd. A dog or wolf alone cannot live for long because they are not as good at hunting alone as felines. Therefore, a domesticated dog sees its owner as the leader of the pack. Even if you treat him harshly, he will not oppose it and will remain loyal. Besides, if you starve, it will eventually leave you. His instinct for survival will tell him to abandon the herd. In fact, the whole event depends on a simple feeding mechanism.
The main reason dogs are considered so loyal is that we can easily train them. You can only train a dog to eat from your hand. As long as he feels your presence around him, he will not eat the food given by someone else, even if he is starving. This is actually their instinct to remain loyal to the herd, manipulated by humans.
We do not know exactly when and how we domesticated dogs. According to one generally accepted theory, dogs or wolves seem to have domesticated themselves. The most likely result is that they realize that there is plenty of food near human settlements and prefer to eat them instead of hunting, and people will benefit from this situation over time.