This question already has an answer here:
Did magical genes result from a slight change in the Human DNA? If so, who was(were) the first wizards? If they were pureblood magical wizards, how are the wizards today still pureblood, assuming that they may have bred with muggles?
Or was magic a sentient form that to earth from the heavens (other planets, species from wherever in the universe) and fuse with themselves with humans to create magical genes?
Did the magical gene distribute itself evenly among earth's population?