Like many things in the series, there seems to be various different lines of evidence that don't all necessarily lead to the same conclusion. It should be kept in mind that there is not necessarily a reason why there should or would be the same amount of students from one year to the next.
Declarações gerais
That said, throughout the series there are consistent indications that there are somewhere between several hundred to a thousand students. These indications come in the form of a couple dozen quotes describing some aspect of the Hogwarts population. Most of the quotes are simply various reiterations of "hundreds of students walking around" or something similar. I don't think that fewer than 300 people would be described as "hundreds". Sometimes it even says "hundreds upon hundreds" which would imply even more students. All those quotes are collected at the end of this post so as not to burden the reader.
In addition to the above general descriptions there are some specific quotes that can give us a more precise estimate:
Carriage Capacity
For instance, there are approximately 100 Thestral carriages, as per Ordem da Fenix Capítulo 10:
Here stood the hundred or so horseless stagecoaches that always took
the students above first year up to the castle.
We usually see something like 4 or 5 students in a carriage, but a passage in the same chapter of Ordem da Fenix indicates that there may have been even 6 or more:
A short distance away, Draco Malfoy, followed by a small gang of
cronies including Crabbe, Goyle, and Pansy Parkinson, was pushing
some timid-looking second years out of the way so that they could get
a coach to themselves.
So there could be something like 500 or more seats for everyone except the first years.
Yule Ball Attendees
Vemos em cálice de Fogo Chapter 23 by the Yule Ball that there were approximately 100 small tables that seat 12 apiece:
The House tables had vanished; instead, there were about a hundred
smaller, lantern-lit ones, each seating about a dozen people.
Even if they wouldn't be filled to capacity, and subtracting the guests, there could easily be 800 students at Hogwarts (especially considering that anyone third year and below who did not have an older date could not attend.) In fact, as we find out in Chapter 22, one of the rumors was that Dumbledore ordered 800 barrels of mulled mead:
The last week of term became increasingly boisterous as it
progressed. Rumors about the Yule Ball were flying everywhere, though
Harry didn’t believe half of them — for instance, that Dumbledore had
bought eight hundred barrels of mulled mead from Madam Rosmerta.
Even if the rumor is not true, as Harry suspected, there would have to be enough people in the castle for such an order to be even conceivable.
O.W.L. Students
We also find in Ordem da Fenix Chapter 28 that when Snape took his O.W.L.s there were over 100 tables, each with one student:
He was standing in the middle of the Great Hall, but the four House
tables were gone. Instead there were more than a hundred smaller
tables, all facing the same way, at each of which sat a student, head
bent low, scribbling on a roll of parchment.
That means that there were more than 100 students just in the fifth year, which could easily translate into 600-800 students in total.
Quidditch Spectators
Perhaps the most precise evidence comes from the number of spectators at the Quidditch match in Prisioneiro de Azkaban Chapter 15. It is described as 3/4 supporting Gryffindor and 200 supporting Slytherin:
Three-quarters of the crowd was wearing scarlet rosettes, waving
scarlet flags with the Gryffindor lion upon them, or brandishing
banners with slogans like “GO GRYFFINDOR!” and “LIONS FOR THE CUP!”
Behind the Slytherin goal posts, however, two hundred people were
wearing green; the silver serpent of Slytherin glittered on their
flags, and Professor Snape sat in the very front row, wearing green
like everyone else, and a very grim smile.
This would mean that there were roughly 800 people attending the match, and throughout the series it seems as if the entire school usually comes to Quidditch matches. If we subtract a few staff members, this would put the total number of students at slightly less than 800.
Gryffindor Quidditch Trials
When Harry holds the trials for the Gryffindor Quidditch team in the beginning of Príncipe Mestiço, his perception is:
Half of Gryffindor House seemed to have turned up
We can attempt to figure out approximately how many people are in Gryffindor by seeing how many people were at the trials and then multiplying by two.
We start off with 50 applicants, as Harry divided them into groups of ten and there were at least five groups:
Harry decided to start with a basic test, asking all applicants for
the team to divide into groups of ten and fly once around the pitch.
The fifth group were Hufflepuffs.
Then there were a couple of Ravenclaws:
There was a pause, then a couple of little Ravenclaws went sprinting
off the pitch, snorting with laughter.
Then there were the seven actual members of the team, as well as everyone else who actually did a tryout. This presumably was not a small number, because it took two hours before they even got up to the Keeper tryouts:
After two hours, many complaints, and several tantrums
The many complaints and several tantrums were presumably all from people who didn't make the team. At the very least, we know for a fact that there were six additional Keeper applicants besides Ron:
None of the first five applicants saved more than two goals apiece. To
Harry's great disappointment, Cormac McLaggen saved four penalties out
of five.
Thus, there were at least 65 students there, and likely many more. Therefore Gryffindor can be presumed to have at least 130 students, though possibly many more. If there is an even distribution among houses then there would have to be well over 500 students in the school.
Defense Against the Dark Arts Class (Fifth Year)
Throughout the series I don't think we ever find Harry having Defense Against the Dark Arts with another house (not counting N.E.W.T classes where everyone seems to be together because there are so few students). Yet in the first Defense Against the Dark Arts Class in *Order of the Phoenix Harry seems to have 30 classmates:
"It was murder," said Harry. He could feel himself shaking. He had
hardly talked to anyone about this, least of all thirty eagerly
listening classmates. "Voldemort killed him, and you know it."
This means that there are 30 students in one year of one house.This certainly does not accord with the conservative theory that there are 10 students per year per house for a total of 280 students. It would however be consistent with a much higher estimate of 800 or more students.
Divination Class
The first time Harry goes to Divination we get the following description of the classroom:
At least twenty small, circular tables were crammed inside it, all
surrounded by chintz armchairs and fat little poufs.
And it wasn't even one person per table:
Harry, Ron, and Hermione sat themselves around the same round table.
Thus, the classroom can seemingly accommodate 60 students. And this is in an elective class, where (at least for Harry's year) it is taught to Gryffindor alone. Even if all the tables were not filled to capacity, the very fact that the classroom has that many seats should indicate the potential for a class to be around that size. According to the conservative estimate of number of students in the school, even if all four houses had class together and every student took Divination the classroom would only be two thirds full. Therefore, it stands to reason that there are actually many, many, many more students in the school.
Flying, Herbology, Potions, and Care of Magical Creatures Class
On the other hand, in Harry's Herbology class with Hufflepuff in Câmara de segredos Chapter 6 there appear to be only 20 students (based on the 20 pairs of earmuffs):
About twenty pairs of different-colored ear-muffs were lying on the
bench.
Likewise, his flying class with Slytherin in Pedra filosofal Chapter 9 also only has 20 students (based on the 20 broomsticks):
The Slytherins were already there, and so were twenty broomsticks
lying in neat lines on the ground.
Likewise, his Potions class wwith Slytherin in Câmara de segredos Chapter 11 also only has 20 students (based on the 20 cauldrons):
Twenty cauldrons stood steaming between the wooden desks, on which
stood brass scales and jars of ingredients.
Similarly, Harry's third year Care of Magical Creatures class with the Slytherins appears to have only had about 20-30 students. In the first lesson we are told that there were a dozen hippogriffs:
Trotting toward them were a dozen of the most bizarre creatures Harry
had ever seen.
And we later find 1-3 students per hippogriff:
Neville ran repeatedly backward from his, which didn't seem to want to
bend its knees. Ron and Hermione practiced on the chestnut, while
Harry watched.
Malfoy, Crabbe, and Goyle had taken over Buckbeak.
The number of students in these classes would seem to indicate that the school is much smaller (only a couple hundred students or so).
To address these small numbers one could perhaps suggest that Ravenclaw got 50% or more of the students in Harry's year – which would explain why Gryffindor has classes with Hufflepuff and Slytherin but never with Ravenclaw (not counting N.E.W.T. classes where all the houses are combined due to the small number of students advancing) – but Ravenclaw does not appear to be overly represented from the (part of) the sorting we see (in which they got three students). Alternatively, Harry's year might be particularly small and the rest of the school had all the hundreds of students, but there does not seem to be any particular evidence for this.
Defense Against the Dark Arts Class (Sixth Year)
In Harry's sixth year his N.E.W.T Defense Against the Dark Arts class is taught to all four houses together. This can be demonstrated as follows:
We know Slytherin was there, by the presence of Malfoy:
"An answer copied almost word for word from the Standard Book of
Spells, Grade Six," said Snape dismissively over in the corner,
Malfoy sniggered), "but correct in essentials.
We know Hufflepuff was there, by the presence of Ernie Macmillan:
"Harry," Ernie said portentously, holding out his hand as Harry
approached, "didn't get a chance to speak in Defense Against the Dark
Arts this morning.
We know Ravenclaw was there based on the following calculation:
In one class, Snape collects their essays and we see that there are 25 of them:
"Before we start, I want your Dementor essays," said Snape, waving his
wand carelessly, so that twenty-five scrolls of parchment soared into
the air and landed in a neat pile on his desk.
In the first class, we find out that at least half the class had been D.A. members:
Although Snape did not know it, Harry had taught at least half the
class (everyone who had been a member of the D.A.) how to perform a
Shield Charm the previous year.
This means that there were at least 13 D.A. members in Harry's year. If we go back to the original D.A. gathering in Ordem da Fenix we are given a complete list of the 28 members:
Harry
Hermione
Rum
Neville
Decano
Lavanda
Parvati
Padma
- Cho
- One of Cho's friends (Marietta)
- Luna
- Katie
- Alice
- Angelina
- Colin
- Dennis
Ernie
Justin
Hannah
Hufflepuff girl Harry didn't yet know (Susan Bones)
- Anthony Goldstein
- Michael Corner
- Terry Boot
- Ginny
- Tall skinny blond boy (Zacharias Smith)
- Fred
- George
- Lee
As you can see from the highlighted names, there were only twelve members of the D.A. in Harry's year that were not in Ravenclaw. Thus, in order for at least half of Harry's Defense Against the Dark Arts class to have been in the D.A. the class must have included Ravenclaw as well.
We can therefore conclude that the total number of students in Harry's year (all four houses) that advanced to N.E.W.T. Defense Against the Dark Arts was 25. It seems somewhat unlikely that more than half the year was unable to advance to N.E.W.T. Defense Against the Dark Arts, so that would put the total number of students in harry's year at somewhere below 50. Assuming even distribution between years, this would be pretty consistent with the most conservative estimates of total number of students – a couple hundred or so.
Knowing Fellow Students
But if indeed there were only a couple hundred students you might expect Harry to at least have a passing familiarity with most, if not all, of them. Yet throughout the series Harry routinely passes by or interacts with students that he does not seem to know at all. In fact, he doesn't learn Susan Bones's name until Ordem da Fenix Chapter 16, which is after presumably having 4 1/2 years of classes with her:
and a Hufflepuff girl with a long plait down her back whose name
Harry did not know;
“Is it true,” interrupted the girl with the long plait down her back,
looking at Harry, “that you can produce a Patronus?”
There was a murmur of interest around the group at this.
“Yeah,” said Harry slightly defensively.
“A corporeal Patronus?”
The phrase stirred something in Harry’s memory.
“Er — you don’t know Madam Bones, do you?” he asked.
The girl smiled.
“She’s my auntie,” she said. “I’m Susan Bones. She told me about your
hearing. So — is it really true?
If there are only 20 students per class that would be very strange. If there were 50-100 or more students in a class it would make sense.
In the same scene we see that Harry barely knows the names of Terry Boot, Anthony Goldstein, and Michael Corner who are all in his year, and doesn't know Zacharias Smith's name at all:
three Ravenclaw boys he was pretty sure were called Anthony Goldstein,
Michael Corner, and Terry Boot; Ginny, followed by a tall skinny blond
boy with an upturned nose whom Harry recognized vaguely as being a
member of the Hufflepuff Quidditch team,
Ron as well clearly did not know Michael Corner or Zacharias Smith:
“Who are you?” said Ron rather rudely.
“Zacharias Smith,” said the boy, “and I think we’ve got the right to
know exactly what makes him say You-Know-Who’s back.”
“Which one was Michael Corner?” Ron demanded furiously.
“The dark one,” said Hermione.
Likewise, Harry does not know Cormac McLaggen in the beginning of Príncipe Mestiço, despite them being in the same house and only one year apart.
there were also two seventh-year boys Harry did not know
"This is Cormac McLaggen, perhaps you've come across each other – ?
No?"
This means that Harry does not know someone whom he has been sharing a common room with for five years. This might be understandable if there were upwards of 200 students in a house; less so if there were only 70 students in a house.
Similarly, Harry does not know Romilda Vane until she introduces herself to him on the Hogwarts Express in Príncipe Mestiço... after sharing a common room with her for four years:
Before he could respond, however, there was a disturbance outside
their compartment door; a group of fourth-year girls was whispering
and giggling together on the other side of the glass.
"You ask him!"
"No, you!"
"I'll do it!"
And one of them, a bold-looking girl with large dark eyes, a prominent
chin,and long black hair pushed her way through the door.
"Hi, Harry, I'm Romilda, Romilda Vane," she said loudly and
confidently.
Even Hermione apparently doesn't know a girl she's been sharing a common room with for more than five years:
Hermione hurried over to Katie's wailing friend and put an arm around her.
"It's Leanne, isn't it?"
Conclusão
Most likely, J.K. Rowling either didn't think it through enough, or just messed up on the calculations, because there are several passages that imply a relatively small number of students yet there is also significant evidence that the total is a lot more than that.
General Quotes
Pedra filosofal Capitulo 7
They followed Professor McGonagall across the flagged stone floor.
Harry could hear the drone of hundreds of voices from a doorway to
the right — the rest of the school must already be here — but
Professor McGonagall showed the first years into a small, empty
chamber off the hall.
ibid
The hundreds of faces staring at them looked like pale lanterns in
the flickering candlelight.
Pedra filosofal Capitulo 10
Hundreds of seats were raised in stands around the field so that the
spectators were high enough to see what was going on.
Câmara de segredos Capitulo 8
A rumble, as though of distant thunder, told them that the feast had
just ended. From either end of the corridor where they stood came
the sound of hundreds of feet climbing the stairs, and the loud,
happy talk of well-fed people; next moment, students were crashing
into the passage from both ends.
Câmara de segredos Capitulo 16
They hid themselves inside it, listening to the rumbling of hundreds
of people moving overhead, and the staffroom door banging open.
Prisioneiro de Azkaban Capitulo 5
Harry, Ron, and Hermione followed the rest of the school along the
platform and out onto a rough mud track, where at least a hundred
stagecoaches awaited the remaining students, each pulled, Harry could
only assume, by an invisible horse, because when they climbed inside
and shut the door, the coach set off all by itself, bumping and
swaying in procession.
Prisioneiro de Azkaban Capitulo 9
One casual wave of his wand and the long tables flew to the edges of
the hall and stood themselves against the walls; another wave, and
the floor was covered with hundreds of squashy purple sleeping bags.
cálice de Fogo Capitulo 15
Hundreds upon hundreds of owls of every breed imaginable were nestled
here on perches that rose right up to the top of the tower, nearly
all of them asleep, though here and there a round amber eye glared
at Harry.
cálice de Fogo Capitulo 17
It felt like an immensely long walk; the top table didn’t seem to be
getting any nearer at all, and he could feel hundreds and hundreds of
eyes upon him, as though each were a searchlight.
ibid
Harry heard the buzzing of the hundreds of students on the other side
of the wall, before Professor McGonagall closed the door.
ibid
Yet how could anyone think that, when he was facing competitors who’d
had three years’ more magical education than he had — when he was
now facing tasks that not only sounded very dangerous, but which were
to be performed in front of hundreds of people?
Goblet of Fire Chapter 19
Admittedly, he didn’t see how Sirius was going to make him feel any
better about having to perform an unknown piece of difficult and
dangerous magic in front of hundreds of people, but the mere sight of
a friendly face would be something at the moment.
cálice de Fogo Capitulo 20
And in no time at all, hundreds upon hundreds of pairs of feet could
be heard passing the tent, their owners talking excitedly, laughing,
joking. ... Harry felt as separate from the crowd as though they were
a different species.
ibid
There were hundreds and hundreds of faces staring down at him from
stands that had been magicked there since he’d last stood on this
spot.
ibid
Harry waited, every fiber of him hoping, praying. ... If it hadn’t
worked ... if it wasn’t coming ... He seemed to be looking at
everything around him through some sort of shimmering, transparent
barrier, like a heat haze, which made the enclosure and the hundreds
of faces around him swim strangely. ...
cálice de Fogo Capitulo 31
Five minutes later, the stands had begun to fill; the air was full of
excited voices and the rumbling of feet as the hundreds of students
filed into their seats.
Ordem da Fenix Capitulo 12
With a whoosh and a clatter, hundreds of owls came soaring in through
the upper windows.
ibid
The bell rang for the end of the lesson. Overhead and all around came
the elephantine sounds of hundreds of students on the move.
Ordem da Fenix Capitulo 14
The sun was high in the sky now and when Harry entered the Owlery the
glassless windows dazzled his eyes; thick silvery beams of sunlight
crisscrossed the circular room in which hundreds of owls nestled on
rafters, a little restless in the early morning light, some clearly
just returned from hunting.
Ordem da Fenix Capitulo 19
They could hear hundreds of footsteps mounting the banked benches of
the spectators’ stands now.
Príncipe Mestiço Capitulo 8
With the usual deafening scraping noise, the benches were moved back
and the hundreds of students began to file out of the Great Hall
toward their dormitories.
Príncipe Mestiço Chapter Chapter 18
He could only suppose that he was missing Malfoy amongst the hundreds
of tiny black dots upon the map.
Príncipe Mestiço Capitulo 19
“Gotta see it from their point o’ view,” said Hagrid heavily. “I
mean, it’s always bin a bit of a risk sendin’ a kid ter Hogwarts,
hasn’ it? Yer expect accidents, don’ yeh, with hundreds of underage
wizards all locked up tergether, but attempted murder, tha’s
diff’rent.
Relíquias da Morte Capitulo 30
“Potter, we’re talking about hundreds of students — ”
Relíquias da Morte Capitulo 31
The sound of hundreds of people marching toward the Room of
Requirement grew louder and louder as he returned to the marble
stairs.
ibid
“I’ve had hundreds of kids thundering through my pub, Potter!”