Ego arises when your sense of Beingness, of "I Am," which is formless consciousness, gets mixed up with form. This is the meaning of identification. This is forgetfulness of Being, the primary error, the illusion of absolute separateness that turns reality into a nightmare.
Ego is always identification with form, seeking yourself and thereby losing yourself in some form. Forms are not just material objects and physical bodies. More fundamental than the external forms —— things and bodies——are the thought forms that continuously arise in the field of consciousness.