Hogwarts is set in a UK system, and so assumes a two stage school process with a transition between primary and secondary schools at the age of 11.
As many have stated above, the UK school system typically comprises two 7-year cycles: primary (4 to 11 years) and secondary (11 to 18 years). The years in primary are usually defined as P1 to P7. The years in secondary are usually defined as numbered year up to 6th, and then as lower 6th and upper 6th for the final two years. Sometimes the final two years are in separate institutions called Sixth Form Colleges.
In the past the transition between the two systems, primary and secondary, was governed by a famous examination called the 11+ (emphasing the importance of this age of transition). Those performing well in the academic styled exams were admitted to Grammar Schools, with an academic ethos, and those performing less well (contested, see below) to Secondary Modern schools with more of a vocational/trades focus. This system was in place from the end of WWII onwards after the Butler Education Act 1944, that made secondary as well as primary education free for all students.
Although this system was very successful by many metrics, the 1960s saw a set of changes prompted by the belief that it was very unfair to stream students at such a young age of 11, and in fact created large barriers to social mobility; analysis showed that the class of the parents, rather than than the ability of the child was the main factor in success in the 11+, often linked to how much the parents could support their own children through the system. Therefore, in most of the UK the 11+ is no longer used, and the secondary system now has Comprehensive Schools that try and cover all these types of education in a single school.
There remains a big debate about the number of comparatively wealthy people who by-pass this more egalitarian system, and send their children to fee-paying schools, which in the UK are counter-intuitively called "public" schools. Arguably Hogwarts is most like one of these elite private schools, like Eton, Harrow and Westminster, which are often centred on a boarding culture. J.K. Rowling herself went to a Comprehensive School, Wyedean School and College, near the border between Wales and England.
In the broader context, there is a long tradition of boarding school literature in British children's literature: school story. This reached its peak in the late 19th and early 20th centuries. So the Harry Potter stories can be seen as a revival of this tradition, albeit with a co-educational (boys and girls) rather than a single sex school, as had been the norm in the tradition.