Moral codes are either (A) natural moral codes, following a simple order of natural relationships among people, things and events, or, in the case of codes supposedly created by or otherwise defined by gods, (B) religion-based, or god-based, moral codes—supernatural codes, unnatural codes, non-natural codes.
For a general discussion of moral codes, see Natural Morality
One description of a natural moral code is thus: S->PS->SS/No man should injure another.
S = Selfishness, wherein an individual seeks to achieve his desires and to maximize his happiness. S is natural; all humans are born selfish, S; S is inherent in human beings; S is therefore natural.
PS = Personal Selfishness wherein an individual seeks to achieve his desires and to maximize his happiness without considering the desires and happiness of other people.
SS = Social Selfishness wherein an individual seeks to achieve his desires and to maximize his happiness by considering the desires and happiness of other people by recognizing that to achieve his desires and to maximize his happiness he needs the ready, willing and able cooperation of other people for which he must be ready, willing and able to cooperate with them by negotiating and seeking to achieve common desires.
There is thus a sequence of S->PS->SS in which natural morality develops.
Thomas Jefferson defined The Essence of All Law thus: The essence of all law is that no man should injure another; all the rest is commentary.
Injury can be defined as a loss of life, limb, liberty, or property.
An innocent man can be defined as an individual who does not intend to injure someone who does not intend to injure him or any other innocent individuals.
Jefferson's The Essence of All Law can be rephrased thus: The essence of all law is that no man should [be allowed to] injure [cause a loss of life, limb, liberty, or property to] another [innocent man]; all the rest [of the law] is commentary. [Note: This rephrasal recognizes that an individual in defense of himself or other individuals may have to injure another non-innocent individual, a criminal, who intends to injure him or other innocent individuals.]
Whenever men do good deeds for other men, we can see S->PS->SS/No man should injure another in action regardless of the claims of the guidance of another moral code.
Why do people follow moral codes?
Why do people follow religious moral codes?
Why do people follow natural moral codes such as described by S->PS->SS/No man should injure another?
There may be many reasons but one stands out above all others: human selfishness.
People who believe in the existence of gods and the existence of god-based morality and the judgment of the gods and the reward/punishment of the gods, including either admission to or denial of an afterlife or the promise of a pleasant or miserable afterlife follow the god-based morality for selfish reasons—to gain the reward and avoid the pain.
People who follow S->PS->S/No man should injure another do so because of S/Selfishness, because they realize that to achieve most of their desires and to maximize their happiness they need the ready, willing and able cooperation of other people for which they must be ready, willing and able to cooperate with those other people to negotiate and to seek to achieve common desires.
So, the motivation for following either god-based morality or natural morality is the same: selfishness.
Because selfishness motivates people, and works with either god-based morality or natural morality, men can be moral because of selfish reasons, men ARE moral because of selfish reasons, and because S->PS->SS/No man should injure another needs no gods, and thus has the lesser complexity for understanding and application, natural morality is the superior morality and therefore is/should be the preferred morality.
Natural morality promises the achievement of desires and the maximization of happiness here and now in this lifetime upon this earth in contrast to the promise of the achievement of desires and the maximization of happiness in another time in another lifetime and someplace other than upon this earth.
Thus, people follow natural morality because they are selfish and they expect that by following natural morality they will achieve many of their desires and maximize their happiness here and now in this lifetime and upon this earth. They recognize that although they are selfish because by S->PS->SS/No man should injure another people need people in terms of being ready, willing and able to cooperate by to negotiating and to seeking to achieve common desires with other people there is a chance of creating a wonderful life in which many if not most if not all their desires are achieved and their happiness is maximized here and now in this lifetime and upon this earth.