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 paternal grandmother was British, and he also has Pennsylvania Dutch ancestry. His maternal grandfather was American, from Minnesota. After his parents divorced in 1980, Musk lived mostly with his father in the suburbs of Pretoria, which Musk chose two years after his parents split up, but now says was "not a good idea". As an adult, Musk has severed relations with his father. He has a half-sister, and half-brother.
During his childhood, Musk was an avid reader. At age 10, he developed an interest in computing with the Commodore VIC-20. He taught himself computer programming at the age of 12, sold the code of a BASIC-based video game he created called Blastar, to a magazine called PC and Office Technology, for approximately $500. A web version of the game is available online.
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 when a group of boys threw him down a flight of stairs and then beat him until he lost consciousness.
Musk attended Waterkloof House Preparatory School, and Bryanston High School before graduating from Pretoria Boys High School. He moved to Canada in June 1989, just before his 18th birthday, after obtaining a Canadian passport through his Canadian-born mother.
At the age of 17, Musk was accepted into Queen's University in Kingston, Ontario, for undergraduate study. In 1992, after spending two years at Queen's University, Musk transferred to the University of Pennsylvania, where in May 1997 he received a Bachelor of Science degree in physics from its College of Arts and Sciences, and a Bachelor of Science degree in economics from its Wharton School of Business. Musk extended his studies for one year to finish the second bachelor's degree. While at the University of Pennsylvania, Musk and fellow Penn student Adeo Ressi rented a 10-bedroom fraternity house, using it as an unofficial nightclub.
In 1995, at age 24, Musk moved to California to begin a Ph.D. in applied physics and materials science at Stanford University but left the program after two days to pursue his entrepreneurial aspirations in the areas of the internet, renewable energy, and outer space. In 2002, he became a U.S. citizen.