Our morality is derived from three primary aspects of our nature. Self, society, and reason.
Self is the easiest component to understand. Something happens to us that we dislike we take to be bad. Something happens to us that we like we take to be good.
Society takes this simple concept of good and bad and projects it to others. There is evidence that our brains are wired to internalize the actions and conditions of others (see mirror neurons). We internalize these observations and empathize with them. Sometimes quite strongly. Due to this internalization of other peoples condition we project our sense of what we consider good or bad for ourselves to their condition. And depending on how connected we feel we consider this harm to other to be good or bad as we would to ourselves.
It is this connectivity that is at the heart of our tendency to for societies. As these social groups grow and expand they we begin to extend our ability to learn and reason things out into our moral sense of right and wrong. We take the simple concepts of right and wrong relating to self and those around us and fathom that there may be other actions which may be right or wrong and that circumstances can change things as well. This becomes the starting point of our forming complex codes of ethics and eventually laws.