Uber lost $5.2 billion in 3 months. Here's where all that money went.

Uber executives at the company's IPO in May at the New York Stock Exchange. AP Photo/Richard Drew Uber posted a $5.2 billion loss on Thursday, its largest ever, sending shares plummeting.

A major chunk of that loss was a consequence of two things: stock-based compensation and driver rewards, both stemming from the company's initial public offering in May.

Other major costs for Uber include research and development, on things like self-driving cars, and sales and marketing, in order to keep growing.

Visit Business Insider's homepage for more stories. Uber lost a whopping $5.2 billion in the second quarter of 2019, the company revealed on Thursday, its deepest quarterly loss ever, thanks to an expensive initial public offering earlier this year. It's a tremendous amount of money for any company, though a major chunk was thanks to one-off expenses, and the spending is set to decline in coming periods, the company said. Still, investors weren't happy with the results, and the stock plunged as much as 8% when markets opened Friday morning. "The big picture is we want to be there any way you want to get around your city, and I think we're well on a path to do so in a profitable way," CEO Dara Khosrowshahi told analysts on a conference call following the results. Most Wall Street analysts viewed the quarter as in line with what they expected, even as certain line items might have disappointed. Some even suggested the big sell-off was a buy-the-dip opportunity. "We see Uber shares as one of the best long-term stories in the Internet and would take advantage of the weakness to add to positions," Lloyd Walmsley, an analyst at Deutsche Bank, told clients. "We think a continued improvement in unit economics and better visibility into the path to profitability could draw more investors to do the work, and given compelling potential upside in a bull case, near term and long term, we would not wait to get involved." Here are the costs that led to Uber's massive loss in the second quarter:

Stock-based compensation: $3.9 billion AP Photo/Richard Drew This was, by far, the largest factor in Uber's loss. The company's income statement included $3.9 billion of such expenses, nearly all of it related to its IPO in May. Uber had handed out restricted shares that vested when it completed its offering; the value of those shares comprised $3.6 billion of its total stock-based compensation expense for the quarter. Many of the recipients of these shares will be eligible to sell their stock soon, depending on when their specific lockup period ends. Lyft, Uber's biggest US competitor, moved its date for that period to end forward to August 19 from a date in September that coincided with the company's earnings quiet period. In the next quarter, Uber expects its stock-based-compensation charges to fall dramatically. "For Q3 2019 stock-based compensation, we expect an expense of $450 million to $500 million," Nelson Chai, the company's chief financial officer, said on the call. Regardless, many investors ignore the expense of stock-based compensation because it is, at least initially, a noncash cost.

Driver rewards: $299 million Drew Angerer/Getty Images Uber also spent heavily on driver rewards connected to its IPO. The company spent $299 million in another onetime charge for those driver payments. Khosrowshahi told CNBC on Friday morning that these one-off charges, while painful, were well-deserved and important to retaining drivers and talent. "The IPO for us was a once in a lifetime moment," he said. "And it was a really important moment for the company. Some of what we did, like the driver-appreciation reward, almost $300 million that we put in the hands of over a million drivers globally, was really important for us to do. It created a messy P&L from an accounting standpoint that I think is hiding underlying trends that are actually very, very healthy for the company."

Research and development: $3.06 billion ($2.6 billion from stock-based compensation) Gene J. Puskar / AP Research and development was Uber's biggest operating expense on its income statement. But much of that expense - $2.6 billion of the $3.1 billion total - came in the form of stock-based compensation, and that figure ballooned because of IPO-related vesting of certain restricted shares. Still, Uber is investing heavily in R&D. Between its Advanced Technologies Group, which is developing self-driving cars in Pittsburgh, Toronto, and San Francisco; New Mobility, which is launching new e-bikes and adding public-transit options to Uber's app; Elevate, the unit dedicated to making flying taxis a reality; and improvements to its core ride-hailing business' dispatching, routing, and fare algorithms; there's plenty to spend money on. Read more: Uber has raised another $1 billion for its self-driving unit, which is now valued at more than $7 billion Here's how Uber defines its research and development spend in regulatory filings: Research and development expenses consist primarily of compensation expenses for engineering, product development, and design employees, including stock-based compensation, expenses associated with ongoing improvements to, and maintenance of, our platform offerings, and ATG and Other Technology Programs development expenses, as well as allocated overhead. We expense substantially all research and development expenses as incurred.

General and administrative: $1.6 billion ($768 million from stock-based compensation) Eric Gay/Associated Press Uber's general and administrative spend includes rent for office space around the world, legal counsel, and human resources. As with its research-and-development expenses, its administrative costs spiked, thanks to the IPO's effect on stock-based compensation. "We expect that sales and marketing expenses will increase on an absolute dollar basis and vary from period to period as a percentage of revenue for the foreseeable future as we plan to continue to invest in sales and marketing to grow the number of platform users and increase our brand awareness," the company said in regulatory filings . "The trend and timing of our brand marketing expenses will depend in part on the timing of marketing campaigns."

Sales and marketing: $1.2 billion ($212 million from stock-based compensation) Reuters / Valentyn Ogirenko Perhaps not surprisingly, Uber spends massive amounts of money on marketing. Even despite laying off 400 employees from its marketing department in July (a move that wasn't counted in this earnings report but will be reflected in the third quarter), the company said this number likely wouldn't be going down. Unlike its research-and-development and administrative costs, relatively little of its sales-and-marketing expenses were in the form of stock-based compensation, so they weren't affected as much by the IPO-related vesting of shares. Read more: Uber marketing employees describe this week's 'bloodbath' when the company laid off 400 employees in more than a dozen countries this week "The reorganization [of the marketing department] is about improving effectiveness, and it's about thinking about where we're going to be for the next five years of the company versus where we come from," Khosrowshahi said on the call. "My expectation is that our marketing spend, I can't speak to the - for the second half of the year, but our marketing spend for the next few years is actually going to both increase and be more effective as a result of the changes that we're making in the marketing organization." In regulatory filings, Uber said its sales-and-marketing spend consisted "primarily of compensation expenses, including stock-based compensation to sales and marketing employees, advertising expenses, expenses related to consumer acquisition and retention, including consumer discounts, promotions, refunds, and credits, Driver referrals, and allocated overhead. We expense advertising and other promotional expenditures as incurred."

Operations and support: $864 million ($404 million from stock-based compensation) Eduardo Munoz/Reuters This line includes many of the driver-focused employees in operations support centers, like Greenlight Hubs, throughout the world. This amount, though small, is likely to decrease going forward, Uber said, as it becomes more efficient in "supporting platform users." It also spiked upward in the quarter because of the IPO-related stock-based-compensation costs.