The Sorting Hat once belonged to Godric Gryffindor. In it were put some brains of the four founders Godric Gryffindor, Helga Hufflepuff, Rowena Ravenclaw and Salazar Slytherin. After that he was able to choose to which house the new students shall belong after the deaths of the founders.
Every year there is a Sorting Ceremony, the hat sings a song which it produced itself and then the sorting begins.
The Sorting Hat tends to sort based on the talents and desires of the students it sorts, rather than the abilities and traits they may later display. It has been known to provide advice, argue with those who it is Sorting, and often gets its way, though not always.
The Sorting Hat may provide the Sword of Gryffindor to those in need.