How much does a student's ranking in their cohort matter for PhD applications? I am from one of the top UK institutions studying mathematics.  I am under the impression that UK universities tend to have a larger cohort (~150 per year) than US but perhaps I am wrong.

I would like to know is there any difference ranking 1st, ranking in top 5 or ranking in top 10 when it comes to PhD applications especially in the US, or is the personal ranking only serves the purpose as a benchmark (say top 5% is enough).

I have heard different theories about this as some would say it's extremely important to get top first or second to get into top graduate programs, and some say that having one or two marks higher than your course mates makes no difference and tells nothing more about your ability.

Thanks for advance.
Your letters of recommendation will be much, much more important than your class ranking. Spend your time on getting the strongest letters you can (and learning how to do this, if necessary).

Source: I have served on grad admissions for a top math department.