On Wednesday night, Google announced it is selling off Motorola Mobility to Lenovo for just $2.91 billion, a couple of years after acquiring the business for $12.5 billion. On the surface it looks like a massive loss for Google, but after taking a deeper dive, this might actually be a great deal after all.

Following the purchase of Motorola Mobility, Google sold Motorola Home to Arris for $2.35 billion, cutting the purchase price down to roughly $10 billion. Motorola also had $3 billion in cash on its book that got directly transferred to Google, so it really becomes a $7.15 billion purchase. After accounting for the $2.91 billion sale price, Google spent $4.24 billion for the rest of Motorola’s business.

However, when you take into account that Motorola has $2.4 billion in deferred tax assets, the purchase price drops to a measly (by Google’s standards) $1.6 billion. Though the status of the deferred tax assets is unclear, if the deal includes Google keeping the deferred tax assets and the patents, which many speculated the deal was really about in the first place, then this is a big coup for Google.

“Google will retain the vast majority of Motorola’s patents, which we will continue to use to defend the entire Android ecosystem,” CEO Larry Page wrote in a blog post.

This deal was, and always will be, about the patents, and those comments from Page are indicative of it. When Google bought Motorola, it gained access to more than 17,000 patents, with perhaps as many, if not more than, 10,000 patents related to mobile communications. Motorola, despite making popular phones such as the Moto X and Moto G, never really fit in with Google’s business, as the company continued to be a drag on results.

Pacific Crest analyst Andy Hargreaves notes that not only will the deal help Google’s margins, but it’ll boost earnings too. “This transaction should be received favorably,” Hargreaves wrote in a note. “First, it helps future margins significantly. We estimated Motorola would lose $816 million in 2014. If this loss disappears completely (it will not because the deal will take time to close), it would increase EPS by about $2.00 in a year when we are forecasting $53.15.”

Google never really had the desire to be in the phone building business, as evidenced by the “confidential” email that managed to get leaked anyway. “But the smartphone market is super competitive, and to thrive it helps to be all in when it comes to making mobile devices,” Page wrote in the email. “It’s why we believe that Motorola will be better served by Lenovo–which has a rapidly growing smartphone business and is the largest (and fastest growing) PC manufacturer in the world.”

By getting rid of Motorola, Google should improve its relationship with Android device makers, most notably Samsung. Google and Samsung recently signed a patent sharing deal, to help stave off the litigation that has plagued the mobile communications device industry for some time now. Samsung and Apple continue to go head to head in patent disputes, with Apple continuing to come out on top in recent trials.

With the recent purchase of Nest, Google finally seems to have gotten the hardware design team it wanted as it moves into other connected products, as well as potentially mobile devices. It’s now abundantly clear that Motorola wasn’t the right team, and Google’s cut its losses.