Hogwarts is divided into four houses, each bearing the last name of its founder: Godric Gryffindor, Salazar Slytherin, Rowena Ravenclaw and Helga Hufflepuff. The houses compete throughout the school year, by earning and losing points for various events, for the House Cup. Each house also has its own Quidditch team that competes for the Quidditch Cup. These two competitions breed rivalries between the houses. Houses at Hogwarts are the living and learning communities for their students. Each house is under the authority of one of the Hogwarts staff members. The Heads of the houses, as they are called, are in charge of giving their students important information, dealing with matters of severe punishment, and responding to emergencies in their houses, among other things. Each year, year level groups of every separate house share the same dormitory and classes. The dormitory and common room of a House are, barring rare exceptions, inaccessible to students belonging to other Houses.
In the early day of Hogwarts, the four founders handpicked students for their Houses. When the founders worried how students would be selected after their deaths, Godric Gryffindor took his hat off and they each added knowledge to it, allowing the Sorting Hat to choose the students by judging each student's qualities and placing them in the most appropriate house. The student's own choices may affect the decision: the clearest example is the Hat telling Harry that he would do well in Slytherin in the first book, but ultimately selecting Gryffindor after Harry asks it not to put him in Slytherin.