Unless you get married to a UK citizen (in which case different laws apply), the earliest you can get a citizenship is after six (6) years after you have first arrived in the UK for the purpose of living there. It doesn't matter whether you are studying, working, or just living in the country on your own being self-sufficient.
Why six? It is because you need to be a Permanent Resident for at least one year before you can obtain a citizenhsip, and you only become a Permanent Resident after living five years in the UK.
You can find the criteria to get naturalized in detail here, more specifically:
- lived in the UK for at least the 5 years before the date of your application
- spent no more than 450 days outside the UK during those 5 years
- spent no more than 90 days outside the UK in the last 12 months
- been granted (...) permanent residence if you’re an EEA national (and you have a permanent residence card or document that shows you have permanent residence)
- had (...) permanent residence if you’re an EEA national in the UK for the last 12 months with a permanent residence card or document that shows you have permanent residence
- not broken any immigration laws while in the UK
And you can find details about Permanent Residence here stating explicitly that being a student is also fine:
You must normally have lived in the UK for a continuous period of five years as:
- an EEA national ‘qualified person’ (worker, self-employed, self-sufficient, student or jobseeker)
However, the definition of 'student' is not as simple as it first appears (from The Immigration (European Economic Area) Regulations 2006):
(d)“student” means a person who—
(i)is enrolled at a private or public establishment, included on the Department for Education and Skills' Register of Education and Training Providers(2) or financed from public funds, for the principal purpose of following a course of study, including vocational training;
(ii)has comprehensive sickness insurance cover in the United Kingdom; and
(iii)assures the Secretary of State, by means of a declaration, or by such equivalent means as the person may choose, that he has sufficient resources not to become a burden on the social assistance system of the United Kingdom during his period of residence.
Expect to have to prove you had health insurance whilst you were a student.
Note, if you are not an EEA citizen similar laws apply, but you need to have an ILR instead of a PR to be eligible for naturalization
Side note: it is true that the original laws are misleading, as they only state you need to be in the UK for five years, and only later tell you about the extra requirement of having a PR for a year, which in itself takes 5 years to obtain. However this six years rule is explicitly stated in the AN Guide Booklet:
But remember that, unless you are married to or the civil partner of a British citizen, you should normally have held permanent resident status for 12 months before applying for naturalisation. This means that you may need to wait until you have been in the United Kingdom for 6 years before you can apply.