Zuckerberg wrote a program called " Facemash " in 2003 while attending Harvard University as a sophomore (second-year student). According to The Harvard Crimson, the site was comparable to Hot and Not and used. "] Facemash attracted 450 visitors and 22,000 photo-views in its first four hours online.  The Facemash site was quickly forwarded to several campus group list servers, but was shut down a few days later by the Harvard administration. Zuckerberg faced expulsion and was charged with security, violating copyrights, and violating individual privacy, and finally the charges were dropped.  Zuckerberg expanded on this initial project that makes a social study tool ahead of an art history final exam.He uploaded all art images to a website, each of which was featured with a corresponding comments section, then shared the site with his classmates, and people started sharing notes. 
Original layout and name of Thefacebook, 2004
A "face book" is a student directory featuring photos and basic information.  In 2003, there were no universal online Facebooks at Harvard, distributed with only paper sheets  and private online directories.   Zuckerberg told the Crimson that "Everyone is talking about a universal face book within Harvard ..." "I think it's all right." a week. " In January 2004, Zuckerberg began writing code for a new website, known as" TheFacebook ", with the inspiration coming from the Crimson about Facemash, stating that" It is clear that the technology is needed to be centralized. Website is readily available ... the benefits are many.
Six days after the site launched, Harvard seniors Cameron Winklevoss, Tyler Winklevoss, and Divya Narendra accused Zuckerberg of intentionally misleading them into believing that he would help them build a social network called HarvardConnection.com. They claimed that he was instead using their ideas to build a competing product. The three complained to The Harvard Crimson and the newspaper began an investigation. They later filed a lawsuit against Zuckerberg, subsequently settling in 2008 for 1.2 million shares (worth $300 million at Facebook's IPO).
Membership was initially restricted to students of Harvard College; within the first month, more than half the undergraduates at Harvard were registered on the service. Eduardo Saverin, Dustin Moskovitz, Andrew McCollum, and Chris Hughes joined Zuckerberg to help manage the growth of the website. In March 2004, Facebook expanded to the universities of Columbia, Stanford, and Yale. It later opened to all Ivy League colleges, Boston University, New York University, MIT, Washington and gradually most universities in the United States and Canada.
In mid-2004, entrepreneur Sean Parker—an informal advisor to Zuckerberg—became the company's president. In June 2004, Facebook moved its operations base to Palo Alto, California. It received its first investment later that month from PayPal co-founder Peter Thiel. In 2005, the company dropped "the" from its name after purchasing the domain name facebook.com for US$200,000. The domain facebook.com belonged to AboutFace Corporation before the purchase. This website last appeared on April 8, 2005; from April 10, 2005, to August 4, 2005, this domain gave a 403 error.
Mark Zuckerberg, co-creator of Facebook, in his Harvard dorm room, 2005
In May 2005, Accel Partners invested $12.7 million in Facebook, and Jim Breyer added $1 million of his own money. A high-school version of the site was launched in September 2005, which Zuckerberg called the next logical step. (At the time, high-school networks required an invitation to join.) Facebook also expanded membership eligibility to employees of several companies, including Apple Inc. and Microsoft.
2006–2012: Public access, Microsoft alliance and rapid growth
On September 26, 2006, Facebook was opened to everyone at least 13 years old with a valid email address. In late 2007, Facebook had 100,000 business pages (pages which allowed companies to promote themselves and attract customers). These started as group pages, but a new concept called company pages was planned. Pages began rolling out for businesses in May 2009. On October 24, 2007, Microsoft announced that it had purchased a 1.6% share of Facebook for $240 million, giving Facebook a total implied value of around $15 billion. Microsoft's purchase included rights to place international advertisements on the social networking site.
In October 2008, Facebook announced that it would set up its international headquarters in Dublin, Ireland. Almost a year later, in September 2009, Facebook said that it had turned cash flow positive for the first time. A January 2009 Compete.com study ranked Facebook the most used social networking service by worldwide monthly active users. Entertainment Weekly included the site on its end-of-the-decade "best-of" list saying, "How on earth did we stalk our exes, remember our co-workers' birthdays, bug our friends, and play a rousing game of Scrabulous before Facebook?"
Traffic to Facebook increased steadily after 2009. The company announced 500 million users in July 2010, and according to its data, half of the site's membership used Facebook daily, for an average of 34 minutes, while 150 million users accessed the site by mobile. A company representative called the milestone a "quiet revolution." In November 2010, based on SecondMarket Inc. (an exchange for privately held companies' shares), Facebook's value was $41 billion. The company had slightly surpassed eBay to become the third largest American web company after Google and Amazon.com.
In early 2011, Facebook announced plans to move its headquarters to the Sun Microsystems campus in Menlo Park, California.   In March 2011, it was reported that Facebook was removing about 20,000 profiles such as spam, graphic content, and underage use, as part of its efforts to boost cyber security.  Statistics by DoubleClick showed that the website was tracked by DoubleClick.   According to a Nielsen study, Facebook had become the second-most accessed website in 2011 in the US behind Google.