In South Asian traditions, the state of being trapped in the illusory belief that one is the ego is known as maya or samsara. In psychology, 'Ego' is presumed as one of the three parts of psychic apparatus defined by Sigmund Freud's structural model. It is also defined by various religions across the world where slight differences also occur in their conceptions. Hinduism and Buddhism have least differences in defining various psychological terms such as self, ego, soul, etc.
Definition (Advaita and Dvaita philosophy; and Dvaitadvaita)
"It is the spontaneous identity of an individual to represent (itself)." According to religious scriptures, it is the characteristic of living beings with a higher level of consciousness that includes humans. Reflection of ego with 'name' is commonly observed in all living beings; that is how they recognize and represent themselves. Ego is also considered as 'identity over identity', e.g., name to a person where name is the secondary identity used by, or for, the person (primary identity or 'self') to represent. It (ego) exists in the state of consciousness.
Definition (A Course In Miracles)
In A Course In Miracles the word ego is used to describe the belief in your dream character, the person who seems to be the doer and be affected by everything within the world. This is contrasted with the true self of the Holy Spirit, formless and ever perfect. The closest thing to a definition of ego in A Course in Miracles is below “The ego is nothing more than a part of your belief about yourself." 
Although ego is generally accepted as a synonym of self, religious doctrine says otherwise. Jivatma is the spontaneous identity part of some self, inherent of all living beings. Ahamkara is the human ego. Jivatma's truest representation cannot exist of itself in some nowadays, because since it is eternal, it is presumably incorruptible, and perfect; whereas ahamkara is more temporal—"any created thing" here or "to do" now. The spontaneity of Jivatma exists in consciousness with ahamkara, but also subsists with sense organs and feeling in an unconscious responsiveness.
In Bhagavad Gita, Shri Krishna says to Arjun that ahamkara must be removed. Veda Vyasa and their religious scriptures also enforce the merging of anyone's jeevatma existence to a supreme soul (paramatman), and anyone's ahamkara existence to its creator.
Ego and consciousness
Higher levels of consciousness are seen in humans and (exceptionally) to a certain extent in some animals, e.g., elephants. Humans are the only entities where ego is observed apparently and up to variable extent in the state of consciousness dividing them further into egoistic, egotistic, egomaniac, etc. 'Spontaneous identity to represent' disappears in all living beings when ego merges with self in the state of unconsciousness and is not recovered until consciousness; though in cases of humans it may occasionally appear in dreams but that is spontaneous and not a part of will (or determination).