ANSWER: The very earliest prehistoric record we have is found in John 1:1-3: "In the beginning was the Word, and the Word was with God, and the Word was God. He was in the beginning with God. All things were made through Him, and without Him nothing was made that was made." The very first beings to exist were God, and the Word (Logos) who was also God. This could have been millions, or billions of years ago. These two spirit beings constituted the God Family and were alone in empty space. There was no physical universe yet. They conceived, designed, and planned.
Part of their creation involved the creation of angels. Angels are immortal spirit beings, composed of spirit. The Old Testament Scriptures show that God created angels before creating the earth (Job 38:4-7). Angels were created with the ability to think, reason, and make choices. They were created free moral agents. After creating them God instructed them in His laws and way of life. However, their creation could not be a finished creation until character was developed in them. It appears that God placed a third of the angels on the earth and gave them the opportunity to share in God's creative activities by finishing the earth. Instead of improving and beautifying the earth they rebelled against God resulting in the ruin and desolation of it (Genesis 1:2). This third of the angels (Revelation 12:4) sinned (II Peter 2:4).
Their leader, the archangel Lucifer (Isaiah 14:12-14) was created perfect, till iniquity was found in him (Ezekiel 28:12-15). Everything that God creates He creates perfectly. God did not create a devil, but an exceptionally beautiful and talented archangel. He became Satan the devil because he rebelled. "Your heart was lifted up because of your beauty; you corrupted your wisdom for the sake of your splendor..." (Ezekiel 28:17).
Lucifer became greedy, jealous, and envious of God. He wanted to rule more than just the earth. He rebelled and attempted to knock God off His throne. "How are you fallen from heaven, O Lucifer, son of the morning! How are you cut down to the ground you who weakened the nations! For you have said in your heart; 'I will ascend into heaven, I will exalt my throne above the stars of God; I will also sit on the mount of the congregation on the farthest sides of the north; I will ascend above the heights of the clouds, I will be like the Most High'" (Isaiah 14:12-14).
He led the angels that had been entrusted to his care to sin and make war against their Maker attempting to overthrow God on the heavenly throne of the universe. "And the angels who did not keep their proper domain, but left their own habitation (the earth), He has reserved in everlasting chains under darkness for the judgment of the great day" (Jude 6). Their minds have become permanently perverted. God did not create demons, but rather beautiful angels who became demons because of sin. Lucifer and his angels were unsuccessful in their coup and were cast back to the earth (Revelation 12:4).