"Musk was short, introverted and bookish."

Elon Musk was born on June 28, 1971, in Pretoria, Transvaal, South Africa, the son of Maye Musk (née Haldeman), a model and dietitian from Regina, Saskatchewan, Canada,and Errol Musk, a South African electromechanical engineer, pilot, and sailor. He has a younger brother, Kimbal (born 1972), and a younger sister, Tosca (born 1974). His maternal grandfather, Dr. Joshua Haldeman, was an American-born Canadian. His paternal grandmother was British, and he also has Pennsylvania Dutch ancestry. After his parents divorced in 1980, Musk lived mostly with his father in the suburbs of Pretoria, a choice he made two years after his parents separated but which he subsequently regretted. Musk is estranged from his father, whom he has referred to as "a terrible human being." He also has a half-sister and a half-brother.

During his childhood, Musk was an avid reader. At the age of 10, he developed an interest in computing while using the Commodore VIC-20.He taught himself computer programming and, by the age of 12, sold the code of a BASIC-based video game he created called Blastar to PC and Office Technology magazine for approximately $500. His childhood reading included Isaac Asimov's Foundation series, from which he drew the lesson that "you should try to take the set of actions that are likely to prolong civilization, minimize the probability of a dark age and reduce the length of a dark age if there is one".

Musk was severely bullied throughout his childhood and was once hospitalized after a group of boys threw him down a flight of stairs.

Musk attended Waterkloof House Preparatory School and Bryanston High School before graduating from Pretoria Boys High School. Although Musk's father insisted that Elon go to college in Pretoria, Musk became determined to move to the United States, saying "I remember thinking and seeing that America is where great things are possible, more than any other country in the world." Musk knew it would be easier to get to the United States from Canada and moved there against his father's wishes in June 1989, just before his 18th birthday, after obtaining a Canadian passport through his Canadian-born mother.