Crude oil prices are diving to levels we haven't seen in years.

Gasoline, a product that's derived from refining oil, is also seeing prices fall. But the pace of decline is not near what we're seeing in oil.

While there is a time lag between when oil is drilled and pumped and when it's refined into gasoline and delivered to consumers, the discrepancy between oil and gas prices has been increasingly significant.

In one year, gas prices have dropped 23%, from $3.55 a gallon, according to data from the EIA. During that time, oil prices have slid from $94 a barrel to around $40 today, a decline of 57%, nearly double the drop in gas prices.

Refining is an intensive, costly process

One of the biggest reasons for this discrepancy is what refiners are doing with the crude oil they receive.

In order to be suitable for a car, crude oil has to go through a refining process. Occasionally these refineries break down or operate below their capacity, creating a bottleneck in supply that causes gas prices to go up.

According to weekly refinery research from Blake Fernandez and Leonard Raymond at energy-investment firm Scotia Howard Weil, however, supply is just fine.

Their research shows that refinery utilization in the US is above both the five-year average and 2014 levels, at around 95%.

Also, refineries in four out of the five regions designated by the EIA are operating above their five-year averages.

So, like crude oil, it seems that refined petroleum is experiencing a supply glut.

The difference is that while oil producers are getting squeezed by low oil prices, the refiners are cleaning up on the difference between their oil costs and the selling prices of their refined products.

Refiners are cashing in on the crack spread

For oil producers, or the upstream businesses, low oil prices mean lower profits. But for refiners, or the downstream businesses, crude oil is a cost. So, if crude oil prices are falling faster than the prices of refined products like gasoline and jet fuel, refiners could actually see profits surge.

This is all capture in something called the "crack spread," which is the difference between what refiners pay for the crude oil they bring in and the price of the petroleum product as it goes out. This spread, or refining margin, is hitting multiyear highs.

According to Fernandez and Raymond's report, crack spreads per barrel for East Coast, Gulf Coast, and West Coast refiners are all above their five-year ranges. The Chicago crack spread, while below the five-year high, is above 2014 levels.

"To-date downstream margins have been supported by declining crude prices largely on the heels of excess supply, while demand has remained robust," said the analysts.

East Coast crack spread is measured using the cost of six barrels of Brent crude oil and subtracting the price of three barrels of gasoline, two barrels of fuel oil (used mainly for home heating) and one barrel of residual oil. Scotia Howard Weil

The West Coast refining margin has jumped from $16.85 a barrel in the third quarter of last year to $36.47 so far this quarter.

The East Coast spread has gone from $8.75 during 3Q of 2014 to $13.45 so far in 3Q of 2015.

Chicago's spread has jumped from $20.55 in 3Q of 2014 to $25.08 so far this quarter.

Fernandez and Raymond explain that part of this margin widening is due to the fact that some large companies refine their own oil.

The EIA reported in June that for the first quarter of this year, integrated companies' upstream profits were down 80%, while downstream profits were the highest in years.

"Profits in the downstream sector, however, were the largest for any quarter since third-quarter 2012, almost $6 billion (95%) higher than in first-quarter 2014, which offset some of the decline from the upstream segment," said the EIA.

Refinery stocks are going bonkers

Independent refiners are doing very well these days. Valero, an independent US refiner, reported a $1.1 billion increase in earnings in the second quarter of 2015 over last year from refining operations:

"The $1.1 billion increase in refining-segment operating income in the second quarter of 2015 compared to the second quarter of 2014 was due to higher margins on gasoline and other refined products (e.g., petroleum coke, propane, and sulfur) relative to Brent crude oil, partially offset by lower discounts on sour crude oils relative to Brent crude oil," said their quarterly filing.

Another refiner, HollyFrontier, posted operating profits of $589 million in the second quarter of 2015, up from $296 million during the same quarter last year, according to the company's SEC filing. The gain was made despite the fact that the sales revenue for the company decreased 31% year over year for the quarter, to $3.7 billion this year from $5.4 billion last year.

The company was able to do this in part due to the drop in cost of goods sold, mostly crude oil, for which the company paid $1.8 billion less — all while increasing refinery utilization from 99.1% to 100.7%. This accounted for approximately half of the costs cut for the company in the quarter.

"Overall gross refining margins per produced product sold increased 20% and 17% over the respective three and six months ended June 30, 2014," said the filing.

So, while the S&P 500 has lost money for investors, refinery stocks have been surging. Check out this chart of refining giants Valero, Tesoro, and Holly Frontier.

So while the refiners are saving from the lower price of oil, a good portion of that is not being passed along to consumers and is instead being added to the crack.