While you would want to consult your university’s international student office to confirm how the UKVI Tier 4 guidance affects you, Cambridge University has a clear example.
When must you leave the UK?
The length of your Tier 4 visa depends on the length of your course, as stated in your Confirmation of Acceptance for Studies (CAS). The Home Office varies this leave if you are government sponsored and then limits your stay in the UK to meet your sponsor's requirements.
The course end date is determined by when the University expects you to have completed all required elements of the course and is the same for all students on that course. It does not include congregation dates.
The Home Office expects you to leave the UK on or before your visa expiry date, unless you have applied to extend your stay or to switch into another immigration category. However, in certain circumstances your Tier 4 visa may be curtailed.
Will your visa be curtailed?
If you complete your course on time (i.e. according to the course end date in your CAS) your visa expiry date does not change and you may remain in the UK until that date.
If you complete your course early (i.e. earlier than the course end date in your CAS) do not assume you can remain in the UK until the date of expiry of your visa. The Home Office requires the University to inform them of every student who completes their course earlier than expected. The Home Office normally limits your permission to the normal wrap-up period of leave. This means that if you have completed your course more than 12 months after the course start date entered on your original CAS, you will receive a curtailment period of 4 months. If you have completed your course in under 12 months, you will receive a curtailment period of two months.
The Home Office advises that if you leave the UK after early completion of studies, or are already outside the UK, your leave to enter or remain will lapse under Article 13(3) of the Immigration (Leave to Enter and Remain) Order 2000 and you may require a visa to enter the UK. Please contact the International Student Team if you have any queries about this.