Microsoft on Tuesday reported revenue declines of 5.1 percent for its fourth quarter, with a massive write-down related to its acquisition of Nokia's handset unit last year leading the company to a record loss of $3.2 billion for the quarter.

Revenue for the quarter ended June 30 was $22.18 billion, down from $23.38 billion for the same quarter last year. The $3.2 billion loss amounted to 40 cents per share.

Commercial cloud revenue was one of the only bright spots. Driven by sales of add-on software services such as its Office 365 and Dynamics CRM Online, commercial cloud was up 88 percent over same period a year prior, reaching a run rate of more than $8 billion in sales.

Microsoft announced earlier this month that it would write down roughly 80 percent of its $9.4 billion purchase of Nokia's mobile handset business, an accounting adjustment that essentially amounts to an admission that it overpaid $7.4 billion in the deal. Excluding the write-down, Microsoft's profit for the quarter was $6.4 billion, for 62 cents per share. Analysts had predicted earnings of 56 cents per share, according to The Wall Street Journal.

Microsoft stock was down as much as 4 percent in after hours trading on Tuesday.