Many years ago, children in the United States were lucky if they could finish elementary school (grades1- 8).
Then some children went to high school (grades 9 -12).
Early in the twentieth century, some kind people said that grades 7 &8 were too old to mix with grades1 - 6, and that grade 9 was too young to mix with grades 10 -12.
So the junior high school was born (grades 7 - 9).
Then 30 years ago or so, some kind people said, "Let's change things again." So they came up with the current system in many American public (government-sponsored) schools:
Elementary 1- 5.
Middle school 6 - 8
High school 9-12