The octane that motorists pay for at service stations may not always be the octane they get.

Millions of gallons of gasoline failed to measure up to their required octane ratings last year based on samples tested by officials in Maryland and Virginia.

Shortchanging on octane (the measure of no-knock quality in gasoline) can cost a motorist an additional nickel a gallon -- or about 50 cents to $1 per tankful.

When there is evidence of octane skimping, authorities can stop sale of the gasoline until the octane has been corrected. But neither Virginia nor Maryland checks the octane of all gasoline sold within its jurisdiction. And in the District of Columbia, officials don't test for octane.

"You would think that with all the profits being made on gasoline that consumers would at least get what they pay for," said Charlotte Newton, president of the Virginia Citizens Consumer Council Inc.

Records of inspections of Washington area gasoline pumps and products show that a majority of gasoline stations comply with price and measure rules. And the sampling of octane indicates that most grades do come within the tolerance range allowed.

"The industry has extraordinary quality control, from my estimation," said Penn Zentmeyer, supervisor of the motor fuel inspection section in the Virginia Department of Agriculture. He said violations of octane requirement rules represent only a small percentage of total gasoline sales.

A spokesman for Mobil Oil said an oil company would never deliberately shortchange on octane.

A review of government inspections of Washington-area gasoline marketing found that:

Gallon or liter measures are frequently incorrect. Forty percent of the pumps checked by Montgomery County this summer failed the measure tests and were ordered repaired. Some pumps were dispensing too little gasoline per gallon and others were despensing too much. As pumps age, they tend to despense more gasoline than the pump registers.

Pumps can be rigged to charge motorists more than the price per-gallon listed on the pump register although there is no indication that any such practice is widespread. Within the last year, operators of three Virginia service stations have been convicted of misrepresenting prices. In one case prosecuted in late 1979, the pump showed a price of 98.9 cents a gallon, but motorists filling up their cars at that pump were being charged $1.01 a gallon because of the way the meter was set.

Of the three problems that motorists may encounter at the gas station pump -- wrong measure, wrong price, wrong octane -- the most difficult to detect is the octane discrepancy. In fact, it is impossible to know, in most cases, whether the motorist has been shortchanged on octane.

Octane levels are expressed in numbers that must be posted on gasoline pumps in compliance with federal regulations. The rules call for each pump to have a yellow-and-black sticker marked with the proper octane number for the gasoline being dispensed. The octane number for regular, unleaded gasoline typically is 87 to 88; for regular leaded, 89 to 91, and for superunleaded, 91 to 93. But each company determines the octane for its own products. Inspection by government officials is aimed at finding out if the octane is as high as the company says.

As cars age, they often need higher octane level to perform properly. When they don't get the octane they need, the engines may ping or knock.

Oil companies boost gasoline octane by adding lead or by additional refining. In either case, the cost to the company increases when octane levels are raised.

There is a marked contrast in the testing and the inspecting that is done in the three jurisdictions here.

Of the three areas, Maryland has the most comprehensive and far-reaching testing program. Virginia lags behind Maryland but is ahead of D.C. The octane analysis done by the jurisdictions is one example of the basic differences in their programs.

In Maryland, for example, the state collected samples of gasoline representing 1.2 billion gallons of gasoline -- or about 63 percent of the total gasoline sales for the state in the last fiscal year. The remaining 37 percent was not sampled for octane skimping.

Laboratory analysis found that samples representing the equivalent of about 7.9 million gallons of gasoline were below the allowed octane tolerance level. A majority of the violations involved supergrade gasoline.

The Virginia testing was much more limited. Less than 1 percent of the gasoline sold in the state was analyzed for octane compliance -- 13.5 million gallons checked out of sales totaling 2.7 billion gallons.

An estimated 155,000 gallons was found below required octane levels in Virginia, based on the samples analyzed.

Both states perform the octane analyses in their own laboratories. But the time required for the process is twice as long in Virginia, where it typically takes three days between collection of the sample and final lab analysis and can take as long as six days. Maryland normally takes only two days between collection and conclusion.

That is enough time, in some cases, for the gasoline to be sold to motorists before the state knows that it is below the required octane level. "It is conceivable that a station could sell out before we caught the problem, but we usually act before that happens," said Marvin Bond, an administrative aide in the Maryland comptroller's office, which runs the octane inspection program.

But that is less likely to happen in Maryland, which collects most of its samples at bulk gasoline terminal facilities, where fuel is stored until delivery to gasoline stations. Virginia, on the other hand, collects most of its samples at retail stations, where operators sometimes sell out their underground gasoline supplies every one to three days.

The tolerance allowed by the states for octane error also varies. Maryland doesn't stop sale on gasoline unless the octane falls more than six-tenths of a point below the octane number posted on the pump. For instance, the gasoline posted as 89.5 octane fuel would pass the state test even if it registered only 88.9 in the analysis -- a tolerance of six-tenths of one point.

Maryland is slightly more generous with the lowgrade gasolines. In the case of the 87 octane fuels, a tolerance of seven-tenths of one point is permitted.

That compares to the full one point tolerance allowed by Virginia.

One result of those variations is that the same batch of gasoline could pass the Virginia octane test but fail the Maryland requirements. And, since the District does not conduct any octane tests, it would be possible for gasoline to fail both Virginia and Maryland tests and then be sold in D.C.

Earl Maxwell, supervisor of the District's gasoline inspection program, said his unit checks station pump gallon measures twice a year but doesn't have the equipment to test octane. As a result, there is no octane analysis by the D.C. government.

New York City, which doesn't have any testing equipment either, found a solution for that by contracting with a private testing laboratory. The city's Department of Consumer Affairs made some surprise visits early this year to seven gasoline terminnals and found "significant" octane shortchanging at the one containing Mobil's super unleaded gasoline.

The analysis of the samples collected on three separate occasions showed that the Mobil octane was 90.45 instead of 92.5 on Jan. 14; 91.25 instead of 92.5 on Jan. 30, and 91.9 instead of 92.5 on Feb. 6.

Mobil ultimately agreed to pay $10,000 to the department for the cost of the investigation. Bob Weiner, a spokesman for the company, said that Mobil didn't intend for its super unleaded to fall short of posted octane levels. He said the octane deficiency resulted from loading errors at the New York terminal, where regular unleaded had been mixed with super unleaded by mistake. The mingling lowered the octane level of the super grade, he said.

"Mobil is too big a corporation to do something like that deliberately," Weiner said.