Apple said it will donate 9 million masks and Facebook is contributing over 700,000, as health facilities seek supplies to protect workers.

Tech companies began stockpiling N95 masks after a recent spate of wildfires in California created dangerous air quality conditions in much of the state.

© Provided by CNBC EAST MEADOW, NEW YORK - MARCH 24: Nassau County police lead a donation drive to collect medical equipment such as N95 surgical masks, nitrile gloves, tyvex suits, antibacterial and disinfecting wipes to battle the coronavirus pandemic at Eisenhower Park on March 24, 2020 in East Meadow, New York. The World Health Organization declared coronavirus (COVID-19) a global pandemic on March 11. (Photo by Al Bello/Getty Images)

When large tech companies including Apple and Facebook announced this week that they'd be donating stockpiles of protective masks to health workers around the world, some people may have wondered why they had them in the first place.

Executives said they had them in storage because of the recent spate of wildfires in California. They were required to have them by law.

In 2019, the state of California's Occupational Safety and Health Standards Board adopted regulation forcing employers to provide respiratory equipment, including N95 masks, for workers when the Air Quality Index (AQI) reaches unhealthy levels.

"Surgical masks or items worn over the nose and mouth such as scarves, T-shirts, and bandannas will not provide protection against wildfire smoke," the rule said. "An N95 filtering facepiece respirator, shown in the image below, is the minimum level of protection for wildfire smoke."

© Provided by CNBC N95 mask

Masks are in short supply around the world as the COVID-19 coronavirus spreads and threatens to overwhelm health systems in the U.S. Hospitals are concerned that their frontline workers are being jeopardized because they don't have the equipment needed to protect them as infected patients start filling emergency rooms.

New York Gov. Andrew Cuomo said Sunday that the federal government needs to nationalize the purchase of needed medical supplies, and said the shortage of masks and other life-saving equipment like respirators is leading to price gouging, as states compete with each other. New York, the hardest hit state so far in the U.S., now estimates it will need 140,000 hospital beds in as little as 14 to 21 days.

Based on the scale of the crisis, tech companies can only fill a small hole in the massive mask shortage. Apple said it is donating 9 million protective masks and other equipment to health workers in the U.S. and Europe. Facebook is providing 720,000 masks, though not all of them are N95. Vice President Mike Pence thanked Apple and other companies at a White House press briefing on Tuesday.

But federal officials said earlier this month that the U.S. health-care system will need up to 3.5 billion N95 respirator masks over the next year.

Ford announced it will partner with 3M and GE Healthcare to begin producing face masks and ventilators to help fill potential shortages caused by the coronavirus. The Centers for Disease Control and Prevention told health workers last week that they can use homemade masks "in settings where facemasks are not available."

Meanwhile, the California wildfires seems like a distant memory given the state of current health crisis, but fire season is just months away and the intensity of the blazes has picked up dramatically in the last few years. During the Northern California fires of 2018, air quality in parts of the region was the worst in the world at the time, and the AQI has reached harmful levels in three straight years.

WATCH: What the ventilator shortage means in the fight against the coronavirus in the U.S.