Harry Potter's Hogwarts school was voted 36th in the online ranking – one place above Edinburgh's 23,000-per-year Loretto School.
And the fictitious school for aspiring wizards scored more than three out of five in all categories ranging from atmosphere to discipline.
Author Rowling describes the imaginary school of witchcraft and wizardry as a co-educational secondary boarding school, with pupils aged between 11 and 17, located in a mysterious site in Scotland.
Now, Hogwarts has appeared on the list compiled by the Independent Schools Network Rankings website – which lists Scotland's most popular plush schools.
Frank Tiarks, managing director of the site, said anyone can nominate a school and put Hogwarts on the table for fun.
He said: "We thought it was nice for the children and for the willing suspension of disbelief."
He added that the site's rankings were not official, but were merely used to give parents an idea about schools when selecting where to send their children.
However, Scots-based Oscar winner Tilda Swinton, who played the white witch in The Chronicles of Narnia, was reported as saying: "I'm loath to say anything good about going to boarding school, which is one of the reasons why I'm not a believer in Harry Potter".