Retail sales in the U.S. rose in July for the first time in four months and topped economists' forecast as demand rose across the board from cars to building materials, suggesting that the biggest driver of the economy is gaining momentum.

Retail sales rose 0.8 percent last month to a seasonally adjusted $403.9 billion, the Commerce Department estimated Tuesday. This is the biggest gain since February and the first in four months. Economists polled by Thomson Reuters had expected retail sales to rise 0.3 percent.

June's figure is revised lower to a 0.7 percent decrease, compared with the initial estimate of a 0.5 percent drop.

Sales of motor vehicles and parts increased 0.8 percent in July. Excluding auto sales, retail sales rose 0.8 percent. Economists had expected ex-auto sales to rise 0.3 percent. Sales at electronics and appliance stores rose 0.9 percent.

Core sales, excluding autos, gasoline and building materials, rose 0.9 percent in July. That's the biggest gain since January.