A record number of people in the UK are living with HIV, with the number of people with the virus reaching nearly 100,000, new figures have shown.

The Health Protection Agency (HPA) said there were about 96,000 people who have the virus - an all-time high. But health officials warned a quarter of people who have the human immunodeficiency virus are not aware they have been infected.

There were 6,280 people diagnosed with HIV in 2011, the HPA said. Nearly half of all diagnoses in 2011 were acquired heterosexually. Of these, more than half were probably acquired in the UK, compared to only 27% in 2002 according to the HPA report.

New diagnoses among gay men reached an all-time high in 2011, with 3,010 men discovering they were infected. The HPA said that one in 20 men who have sex with men in the UK now have HIV, while the figure soars to nearly one in 12 in London.

Black African people are also at a higher risk, the HPA said, with 37 per 1,000 living with the infection - overall HIV prevalence in the UK was 1.5 per 1,000 people.

Dr Valerie Delpech, HPA head of HIV surveillance, said: "These figures are a reminder of how vital safe sex programmes remain. Promoting HIV testing and condom use is crucial to tackling the high rates of transmission, late diagnosis and undiagnosed HIV still seen in the UK.

"National HIV Testing Week is a great opportunity to encourage people to get tested. We also encourage clinicians to take every opportunity to offer the test to those in higher risk groups and, in high prevalence areas, to all general medical admission and new GP registrants.

"The good news is that with the excellent services and treatments available nowadays, if diagnosed and treated early someone with HIV can look forward to a normal lifespan, as well as protecting their sexual partners from infection. That's why it is vitally important that anyone who has been at risk gets an HIV test, and that those in higher risk groups get screened regularly."

Deborah Jack, chief executive of the National AIDS Trust, said: "What is striking about the HPA's data is how it really shows both our successes and our shortcomings in tackling HIV in the UK.

"On the one hand, we can hail treatment as a real success story. Treatment is effective, people diagnosed with HIV can access it easily, and it is working in keeping the virus under control. However, when it comes to increasing the uptake of testing - the gateway to treatment - our services are patchy, inconsistent and ultimately we are still failing to make any significant headway in tackling the high rates of undiagnosed HIV."