Sigmund Freud’s psychoanalytic theory is that human mind is composed of three elements – Id, Ego and Super ego that constantly co-operates and wrestle with each other resulting in the net human behavior. Id caters to most basic instincts such as food and sex. Super ego is something that is developed as a part of parental/societal upbringing. Ego is what makes a balance between the two elements without trying to disappoint any of the two. It is best explained by a figure, which I am putting here, from this site.
Of course, Sigmund Freud’s theory has been discredited since then, but still this piece provides a perspective to understand human behavior.