Economists polled by Reuters had expected the data to show consumer prices rose at an annual rate of 2.3% in July following a 2.5% rise in June.
Sterling showed little reaction to the figures as investors judged the data was likely to represent a blip in a generally rising trend for inflation.
Earlier this month the BoE said it expected inflation to jump to 4.0% around the end of the year, which would be a decade high. But the BoE said it still thought the jump in inflation would prove to be temporary.
The ONS data showed signs of continued inflation pressure in prices paid and charged by factories.
Output costs rose more quickly than in June and by more than the economists polled by Reuters had expected, increasing by 4.9% compared with July last year. Input costs also rose by more than expected, jumping by almost 10%.
For a look at all of today’s economic events, check out our economic calendar.
(Reporting by Andy Bruce; Editing by William Schomberg)