The rising stock market has pushed America's millionaire population close to its all-time high before the recession.
According to data from Spectrem Group, the Illinois-based wealth research firm, there are now 8.99 million United States households whose net worth totals $1 million or more (not including primary residence). That's up from 8.6 million in 2011 and just short of the all-time record set in 2006, when the US had 9.2 million millionaire households.
(Read more: 'Wealth effect' driven more by homes than stocks)
The stock market's rise has been the biggest driver of millionaire creation. With this year's gains, Spectrem said, the US may have already exceeded its all-time record.
Most of the benefits from rising stocks have gone to the wealthy, since the top 10 percent of Americans own more than 80 percent of all stocks, according to research from Edward Wolff of New York University. But the recent stock surge has also created a new gap within the wealthy, or at least between millionaires and the so-called affluent.
According to Spectrem, the number of households worth $1 million or more and $5 million or more is near the record. But the number of households worth $500,000 or more (the affluent) is much lower than the record in 2007. There are 14.3 million households worth $500,000 or more — down from 15.7 million in 2007.
Why the growing wealth gap within the wealthy?
Catherine McBreen, president of Spectrem Group's Millionaire Corner, said that millionaire households held more stocks — and therefore have benefited more from the market's run-up. It's not just a matter of money. Wealthier households also tend to make better investments, or at least more bullish ones, staying in the market during the recession while less wealthy investors bailed out.
Affluent households had more than half their investable assets in some kind of equities in 2005, but in 2012 it dropped to a third. Millionaire households have 71 percent of their investable assets in some form of equities — up from 61 percent in 2005.
(Read more: Surging stocks gives ski home market a lift)
"The reason the affluents haven't recovered as quickly is their stock holdings," McBreen said. "Many of them simply pulled out of the market. They have more cash. But more of the high-net-worth households stayed in."
She said the millionaire households were more likely to be older and retired, so they could afford to keep more money in the market.
"The affluent group may be high earners, but they also might have high expenses like college tuition."
More from our partners at CNBC: