In order to have a right of residence in the UK as a student you have to have comprehensive sickness insurance (CSI).
The European heath insurance card (EHIC) obtained from your country of residence is acceptable evidence of CSI, if your stay in the UK is to be temporary. If your stay is to be permanent, or you are unable to get an EHIC card from your country of residence, you will need to obtain separate insurance.
Home Office guidance contains detailed information (on pages 30 - 38) on what the UK government considers acceptable evidence of CSI.
If you are applying to have your right to reside confirmed on form EEA(QP) or CR1 and are using the EHIC (because your stay is not intended to be permanent), you will also need to send a letter (called a 'statement of intent’ in the application form) confirming that you do not intend to stay in the UK permanently.
The UK government does not accept entitlement to the National Health Service as sufficient evidence, so you will need to get the EHIC before you leave your country of residence, or obtain the adequate insurance. The government has produced a leaflet about EHIC and access to medical treatment while in the UK.
Family members of students are now also required to obtain CSI. The Home Office has required dependants of students to have comprehensive sickness insurance since 22 June 2015. Information about the requirement for family members to obtain CSI and the transitional measures the government introduced are contained in Home Office guidance.
The Free Movement blog has published a post containing useful information about comprehensive sickness insurance following the UKs EU referendum result.