Octane rating is measured using a standardized test engine that simulates the conditions inside a typical internal combustion engine. The test measures the fuel's ability to resist knocking under various operating conditions, and the resulting octane rating is the average of these measurements.