What is the difference between ego and confidence?
Depends on what you mean by “confidence”. Confidence as prediction, e.g. “I am confident that if I drop this apple it will fall to the ground” has nothing to do with ego - it’s just intelligence. Discerning patterns, making predictions and executing on them is the basic function of the brain, and it’s the same for all animals.
But ego is a human phenomena. Confidence as a personality trait, that is, projecting an “aura” of strength, success, superiority, invulnerability, ability, abundance, being sure of oneself - so basically the opposite of what you would call “insecurity” - is ego.
Such confidence and insecurity are just two sides of the same coin, there is no difference between them. The only difference is that one is judged as a positive (desirable) trait and another as a negative (undesirable) one. Other examples of such pairs include bravery and cowardice, altruism and selfishness, arrogance and humility. These are all the same, and they are not seen as different in egolessness.