Income inequality has increased rapidly in the last few decades, as the gains from globalization, technology, and political changes have flowed largely to top earners. At the same time, wages among earners in the lower and lower-middle of the income scale have stagnated.

And here’s the scary thing: These trends are likely to speed up in the next 10 years, according to consulting firm Bain & Company. By 2030, automation will eliminate up to 25% of all jobs in the U.S., hitting those at the bottom hardest. It forecasts that the benefits of automation will go mostly to the top 20% of earners as well as to investors funding artificially intelligent equipment.

Bain expects automation to speed up for two interlocking reasons. First, companies are likely to face a shortage of workers in the next decade, encouraging them to invest in machines. The long period of labor force growth starting in the 1950s is coming to an end, it says. The expansion of the labor force from women entering the workplace, the emergence of China and India, and the baby boomer generation, isn’t likely to be compensated by other trends, like people working longer or increased immigration.

Second, automation is becoming more sophisticated, enabling companies to shift more roles more cheaply (“humanoid robots are likely to reach commercialization early in the next decade,” Bain says). Retailers, for example, can replace almost their entire on-floor staff, from cashiers to salespeople. And what’s not sold in stores can be sold online and serviced by drones, self-driving trucks, and people-less warehouses. Even professional jobs are at risk, Bain says. Law firms are already using algorithms to scan legal documents. Financial services firms are employing machine learning to do work previously done by human analysts.

Automation, though, will be a double-edged sword for companies, Bain says. On the one hand, it will boost productivity and short-term profits. On the other hand, it will hollow out demand: Fewer workers means fewer people with the means to buy products. Twenty-five percent of the workforce equates to about 40 million lost jobs. By comparison, the recent recession, from 2008 to 2010, eliminated just 9 million jobs, or 6.3% of U.S. employment.