It is difficult to speak of ancient Egypt in concrete terms because of the great length of Egyptian history and culture, which spanned a period of almost 3,800 years and over 30 dynasties. As such it can’t be treated monolithically. Still we can recognize certain themes which repeat themselves over the ages, especially in magic and religion which are slower to change.
In ancient Egypt, magic and religion were both part of a broader holistic worldview which also included medicine, astronomy, law, politics and beyond. It is hard to even use the word magic in the context of Egypt, since our word magic comes from the Greek μαγεία, which carries a connotation of trickery, malice or charlatanism. In Egyptian thought, there was no such thing as evil magic. To them, magic itself was deified in the person of Heka. Heka was often depicted in cooperation with the Sun and other gods of creation, and was the power they possessed. So, magic was an integral part of their religion. Because their magic, Heka, was a god, there is no place in Egyptian life where magic was illegal, except if used against the pharaoh (which to them would be blasphemy).
Magical activity was present in almost every facet of Egyptian life. Scholars usually identify three aspects of magical practice: apotropaic, curative and transformative magic. Magic was conducted by all manner of people: priests, physicians, local wise men and the pharaoh were all magicians. It was this group of practitioners who were able to summon gods and the liminal beings we would now refer to as demons. Spells for protection can be found on numerous objects, amulets, papyri, coffins, jars, books, murals and figurines for example. Curative magic was used for healing, and spells are often found on statues meant to heal the sick. Medico-magical texts were used in earnest by physicians. Transformative magic, equally popular around the rest of the Mediterranean, was used in the form of not only love and binding spells, but for Egyptians in the Books of the Dead where the deceased would use magic to transform themselves into a god, a plant, a bird or a perfected spirit.
Magical characters, tools or spells can often be identified by their common elements, especially by the presence of the serpent. Could this have also shown how Egyptian magic was understood by other cultures such as the magical battle between Aaron the the court magicians (Ex. 7:9-12)? Gods, magicians, priests and demons could be seen with serpent wands and other attributes if they were performing spells.
How were gods and demons distinguished? They were often represented in similar forms. Gods appeared in myths of creation whereas demons did not. Gods took care of mortals both living and deceased. Demons could communicate with humans but mainly they just needed to be appeased. Gods were also distinguished by their worship in cults, and so they had a more fixed iconography.
There is an issue of translation of modern to ancient concepts and terms. The modern idea of demons is formed by the Judeo-Christian sense of an evil spirit sent to punish sinners, or as symbols of temptation. The ancient Greek δαίμων served as an intermediary between gods and mortals.
“For the divine does not mix with the mortal, and it is only through the mediation of the daimones that mortals can have any interaction with the gods, either while awake or asleep.” -Symposium, 202d, 13-203a
This fits well with the Egyptian idea of demons as liminal figures who communicate between the world of the main gods and humans. While the Greeks distinguished between good and bad demons, the Egyptians mainly did not. These spirits were guardians and servants of greater gods. They were often depicted in mortuary settings such as tombs and sarcaphogi, because they were known to guard specific regions or gates of the netherworld. From the 1st century BCE, coffins were often used similarly to papyrus by being covered in written spells. The Egyptians wanted these spells as close to the body as possible. They could only be dangerous to the one who did not have the specific knowledge needed to approach them. This knowledge was contained in spells written in papyri and coffins, which listed their names and told which gates they guarded. Their names often illustrated their appearance or function, such as “The Hearer”, “Sad of Voice”, “One Who Stretches Out His Brow”, “One With Vigilant Face”.
Demons could be conjured to protect from other demons, although malicious demons are never depicted in Egyptian art. Wandering spirits, bringers of disease, and godly messengers all fell under this category of demon. One XIX Dynasty headrest depicts demons with the head of a crocodile or vulture, spitting out serpents, holding snakes and daggers, which was meant to ward off evil spirits. These more malicious beings were controlled by the main gods. Demonizing an illness may have psychologically helped patients cope with their suffering, which is why we have so many spells where medical prescriptions are also included. Egyptian doctors used magical spells together with medical knowledge to great effect.