By Alexandria Sage and Arathy S Nair

SAN FRANCISCO (Reuters) - Cisco Systems Inc said it would cut nearly 7 percent of its workforce, posting charges of up to $400 million in its first quarter, as the world's largest networking gear maker shifts focus from its legacy hardware towards higher-margin software.

The gradual move to fast-growing sectors such as security, the Internet of Things and the cloud is a response to sluggish demand for Cisco's traditional lineup of switches and routers from telecom carriers and enterprise customers, amid intense competition from companies such as Huawei and Juniper Networks Inc.

Savings from up to 5,500 job cuts would be reinvested into key growth areas, Cisco said.

"We think this is partly an effort by (CEO) Chuck Robbins to put a stake in the ground and send a message that this is going to be a leaner, meaner Cisco that is focused on driving software and recurring revenue business," said Guggenheim Securities analyst Ryan Hutchinson.

Revenue at the company's routers business fell 6 percent in the fourth-quarter ended July 30, while switching unit revenue was up 2 percent. Orders from service providers fell 5 percent, while revenue in emerging markets fell 6 percent, Cisco said.

Cisco projected flat revenue in the first quarter and gave an earnings forecast that was shy of analysts' estimates, saying it expected adjusted earnings of 58 cents to 60 cents per share, versus Wall Street estimates of 60 cents.

"We're uncertain how to model any improvement in those two (segments) in particular going forward," Robbins told analysts on a call, speaking of service providers and emerging markets.

Robbins, who took over from John Chambers in July last year, has been steering Cisco toward more software and subscription-based services. Security, which Robbins said was the top priority of all its customers, posted a revenue gain of 16 percent in the quarter.

Gross and operating margins also improved in the fourth quarter, reflecting cost savings, Cisco said.

"It's part of what we're driving in our shift to software," said Chief Financial Officer Kelly Kramer. "Those businesses have great margins and it's part of the overall transition."

Cisco, which is also betting on acquisitions to fast-track growth, has made 10 acquisitions since Robbins began as CEO, according to FactSet StreetAccount data, from Internet-of-Things startup Jasper Technologies to cloud security provider CloudLock.

Shares of the company were down 1.4 percent in after-hours trade to $30.30.

The shares had gained 13.2 percent this year through Wednesday's close, compared with the 6.8 percent increase in the broader S&P 500 index.

Cisco's fourth-quarter net profit rose to $2.81 billion, or 56 cents per share, from $2.32 billion, or 45 cents, a year earlier. Excluding items, the company earned 63 cents per share.

Revenue fell 1.6 percent to $12.64 billion.

Analysts on average had expected a profit of 60 cents and revenue of $12.58 billion, according to Thomson Reuters I/B/E/S.

Cisco, which expects to start laying off employees from the first quarter, said it will take a charge of about $325 million to $400 million in the quarter. On the whole, the company expects a pretax charge of $700 million.

Hutchinson said it was "relatively unlikely" there would be more job cuts until the end of the fiscal year, barring unforeseen macroeconomic events.

Technology news site CRN, citing sources, first reported on Tuesday that Cisco planned to lay off about 14,000 employees, or nearly 20 percent of its workforce.

(Reporting by Arathy S Nair and Anya George Tharakan in Bengaluru; Editing by Sriraj Kalluvila, Bernard Orr)