Consumers will pay the highest Fourth of July gasoline prices in six years, but pump prices would be far higher if not for dramatic changes in the U.S. oil industry.
Both the production and refining sides of the industry are contributing to a better supply environment, thanks to the oil shale boom and significant expansion of the U.S. refining industry in the last several years.
Prices are expected to go lower this summer, and by Labor Day could be 7 cents to 12 cents cheaper per gallon than the current national average of $3.67 per gallon.
"Without hurricanes, I would say Labor Day, I would be looking at something in the $3.55 to $3.60 neighborhood. I think the real decline always occurs in the last 100 days of the year," said Tom Kloza, oil analyst with GasBuddy.com.
U.S. refining capacity—17.9 million barrels—is at the highest level it's been in 33 years, when it was briefly more than 18 million barrels. For a nation that was once concerned about a lack of new refineries, the industry has been expanding existing facilities, adding more than 2 million barrels a day capacity since the late 1990s.
"It's the highest since 1981. That says to me rather than building new refineries, we've just expanded existing ones to get the economies of scale," said Andrew Lipow, president of Lipow Oil Associates. "In 1981 there were 341 refineries." Now, there are 142.
"A lot of 1981's capacity was not complex, or sophisticated. Back in 1981, we weren't exporting about 1.5 million barrels a day of diesel and gasoline," said Kloza.
The U.S. exports, which go to Europe and South America, are near record levels, but they could increase. "The refining capacity number may go up in the next couple of years. There are a lot of studies that say if we don't lift the export ban on crude, we build another half a million barrels a day or even a million barrels a day of refining capacity in the U.S., and we'll become more of an export nation because our crude prices and natural gas prices are cheaper than everybody else. It's a slight edge, but it's an edge," Kloza said.
Gasoline prices typically decline between Memorial Day and the Fourth of July, but this year prices rose, as the Iraq situation drove up crude oil prices, Kloza said.
Refinery utilization is also rising as the industry brings more capacity back online, some of which was offline due to routine maintenance. Refining utilization rose to 91.4 percent, and gasoline stockpiles fell by 1.2 million barrels, in the week ended June 27, according to the Energy Information Administration.
According to Platt's, a large crude oil unit at Phillips 66's plant in Montana is adding 58,000 barrels a day after going offline due to a fire June 11.
Exxon Mobil restarted a unit June 12 at its 200,700 barrel-per-day refinery in Chalmette, Louisiana, after maintenance, and Exxon also returned its Beaumont, Texas, refinery to normal operations last week after planned work, according to Platt's.
"They're storming back, and the industry is running at almost 90 percent," said oil analyst John Kilduff of Again Capital.
U.S. oil production has grown to about 8.6 million barrels a day recently, more than a million barrels a day greater than last year.
"We're on track to become the world's largest oil producer, which is incredible," said Kilduff.
The U.S. production has displaced West African light sweet crude that was being shipped to East Coast and Gulf Coast refineries. That oil is now coming from the Bakken in North Dakota and elsewhere. Oil from Canada is feeding Gulf Coast and California refineries.
As more North American oil is being used, the price difference between the international benchmark Brent and West Texas Intermediate and other U.S. grades is shrinking. However, that spread widened when Syrian militants seized parts of Iraq. But the differential narrowed again when the U.S. allowed the export of condensates, a minimally processed, lightweight petroleum byproduct.
Oil has been drifting lower, WTI was trading at $104.89 per barrel early Wednesday, while Brent was trading in New York at $111.55 per barrel. Brent weakened Wednesday on a possible return of Libyan oil exports after rebels said they could open two oil terminals.
"I think as long as the Iraq situation holds, I believe they're (gasoline prices) going down, potentially significantly," said Kilduff.
Read MoreAmerica's favorite gas stations
Kloza said the U.S. production is offsetting some geopolitical pressure on prices. "If we didn't have the domestic shale oil boom, right now the noise from Iraq and the problems with Libya, Sudan, Nigeria, we'd be paying regularly over $4 as a nationwide average," said Kloza.
Lipow said the U.S. refining industry is in good shape, and has a good future. "We're exporting more, and we're processing more crude, and U.S. demand has declined since 2007," said Lipow. Gasoline demand has been dropping as more fuel-efficient cars replace aging vehicles, and cars will continue to get more efficient.
"We're in better shape versus the rest of the world than we have been in 20, 30 years," he said.
"Even though we haven't built refineries, we continue to do small expansions on existing facilities. As we go forward, refiners such as Valero, Tesoro and Marathon have projects underway to increase refining capacity."
—By CNBC's Patti Domm.