To the best of my knowledge is never stated directly, but it is implied that the students are sorted into roughly equal numbers in the 4 houses at Hogwarts. There are 7 years and each house has about 10 students per year, or 280 students at the school at any one time, assuming constant class sizes and no dropouts.
If all of the students ride the Hogwarts Express and the cars are standard size, then it has 9 compartments per car, each of which can hold at least 4 students. In this case, the train only needs 8 passenger cars to hold everyone comfortably at 4 passengers per compartment. A normal passenger compartment seats 6, but in the books we almost never see this - it's usually 4 or 5 students per compartment, and sometimes only two.
From the Film: The train, at 4 passenger cars, is not big enough to fit the students.
When we see the Hogwarts Express in the movies it only has 3-4 passenger cars, each of which has 8 windows, and presumably 8 passenger compartments per car as a result - far too few for comfortable seating unless it is magically larger inside than outside, such that compartments are possible on both sides of the train, unlike a normal compartment car. Even then, the train would be right at the capacity for students. (4 cars x 16 magical compartments per car x 4 students per compartment = 256 students)
UPDATE:
From the Books: The train, at 6-7 passenger cars, is just about right for the calculated student population.
Robert Flock, in his answer below, was able to find a reference from the novels to help. Order of the Phoenix, Chapter Ten: “Luna Lovegood” The book describes Harry being goggled at while looking for a seat on the train.
“After he had met this behavior in five consecutive carriages”
He then finds a seat shortly thereafter in the last car on the train. This means that there are six or seven cars. Assuming the same non-magical cars as above, 6 cars with 9 compartments per car each would require an average of just over five students per compartment, or about four and a half if the train had seven passenger cars. This is much more realistic based on the known student population.