Gates was born in Seattle, Washington, on October 28, 1955. He is the son of William H. Gates Sr.[b] (b. 1925) and Mary Maxwell Gates (1929–1994). His ancestry includes English, German, Irish, and Scots-Irish. His father was a prominent lawyer, and his mother served on the board of directors for First Interstate BancSystem and the United Way. Gates' maternal grandfather was J.W. Maxwell, a national bank president. Gates has one older sister, Kristi (Kristianne), and a younger sister, Libby. He is the fourth of his name in his family, but is known as William Gates III or "Trey" because his father had the "II" suffix. The family lived in the Sand Point area of Seattle in a home that was once damaged by a rare tornado when Gates was nine years old. Early on in his life, Gates observed that his parents wanted him to pursue a law career. When Gates was young, his family regularly attended a church of the Congregational Christian Churches, a Protestant Reformed denomination. The family encouraged competition; one visitor reported that "it didn't matter whether it was hearts or pickleball or swimming to the dock ... there was always a reward for winning and there was always a penalty for losing".
At 13, he enrolled in the Lakeside School, a private preparatory school and wrote his first software program. When Gates was in the eighth grade, the Mothers' Club at the school used proceeds from Lakeside School's rummage sale to buy a Teletype Model 33 ASR terminal and a block of computer time on a General Electric (GE) computer for the school's students. Gates took an interest in programming the GE system in BASIC, and was excused from math classes to pursue his interest. He wrote his first computer program on this machine: an implementation of tic-tac-toe that allowed users to play games against the computer. Gates was fascinated by the machine and how it would always execute software code perfectly. When he reflected back on that moment, he said, "There was just something neat about the machine." After the Mothers Club donation was exhausted, he and other students sought time on systems including DEC PDP minicomputers. One of these systems was a PDP-10 belonging to Computer Center Corporation (CCC), which banned four Lakeside students – Gates, Paul Allen, Ric Weiland, and Kent Evans – for the summer after it caught them exploiting bugs in the operating system to obtain free computer time.
At the end of the ban, the four students offered to find bugs in CCC's software in exchange for extra computer time. Rather than use the system via Teletype, Gates went to CCC's offices and studied source code for various programs that ran on the system, including programs in Fortran, Lisp, and machine language. The arrangement with CCC continued until 1970, when the company went out of business. The following year, Information Sciences, Inc. hired the four Lakeside students to write a payroll program in COBOL, providing them computer time and royalties. After his administrators became aware of his programming abilities, Gates wrote the school's computer program to schedule students in classes. He modified the code so that he was placed in classes with "a disproportionate number of interesting girls." He later stated that "it was hard to tear myself away from a machine at which I could so unambiguously demonstrate success." At age 17, Gates formed a venture with Allen, called Traf-O-Data, to make traffic counters based on the Intel 8008 processor. In 1972, Bill Gates served as a congressional page in the U.S. House of Representatives.
Gates was a National Merit Scholar when he graduated from Lakeside School in 1973. He scored 1590 out of 1600 on the Scholastic Aptitude Tests (SAT) and enrolled at Harvard College in the autumn of 1973. He chose a pre-law major but took mathematics and graduate level computer science courses. While at Harvard, he met fellow student Steve Ballmer. Gates left Harvard after two years while Ballmer would stay and graduate magna cum laude. Years later, Ballmer succeeded Gates as Microsoft's CEO. He maintained that position from 2000 until his resignation from the company in 2014.
In his second year, Gates devised an algorithm for pancake sorting as a solution to one of a series of unsolved problems presented in a combinatorics class by Harry Lewis, one of his professors. Gates' solution held the record as the fastest version for over thirty years; its successor is faster by only one percent. His solution was later formalized in a published paper in collaboration with Harvard computer scientist Christos Papadimitriou.
Gates did not have a definite study plan while he was a student at Harvard, and he spent a lot of time using the school's computers. Gates remained in contact with Paul Allen, and he joined him at Honeywell during the summer of 1974. The MITS Altair 8800 was released the following year. The new computer was based on the Intel 8080 CPU, and Gates and Allen saw this as the opportunity to start their own computer software company. Gates dropped out of Harvard at this time. He had talked over this decision with his parents, who were supportive of him after seeing how much their son wanted to start his own company. Gates explained his decision to leave Harvard, saying "...if things [Microsoft] hadn't worked out, I could always go back to school. I was officially on [a] leave [of absence]."