Few people are aware the San Francisco has had a tax provision in its municipal code since 2004 that requires companies to pay a payroll tax on gains from employee stock options. No one pays it, and San Francisco hasn’t enforced it to date, but companies are becoming increasingly agitated that the city may change that policy at any time. The number of high profile and high value startups based in San Francisco – like Twitter and Zynga – may be too big of a temptation for the city to ignore.

Recently, I heard San Francisco Mayor Ed Lee on our local NPR station talking about how important it was to keep Twitter’s headquarters in San Francisco. To those worried that the recent talks between Twitter and the City were stalling, his words must have been reassuring. But if Lee really wants to keep Twitter– and thousands more tech jobs– in San Francisco he needs to defuse this much bigger ticking tax time-bomb now. This isn’t just about keeping Twitter in San Francisco– this has ramifications for San Francisco’s entire startup ecosystem.

To be clear, this is not a trend. Even the federal government considers taxing these options off the table, and we haven’t been able to find a single city in the United States with such a far-reaching tax policy. This would create potentially huge costs for startups that they can sidestep simply by moving a few miles to the North, East or South. If enforced, expect an exodus of San Francisco jobs to surrounding areas.

The provision: Section 902.1 of the San Francisco Business and Tax Code. It was amended in 2004 to include stock options. Here’s the relevant text of the provision (bolding added):

SEC. 902.1. – PAYROLL EXPENSE. (a) The term “Payroll Expense” means the compensation paid to, on behalf of, or for the benefit of an individual, including shareholders of a professional corporation or a Limited Liability Company (“LLC”), including salaries, wages, bonuses, commissions, property issued or transferred in exchange for the performance of services (including but not limited to stock options), compensation for services to owners of pass-through entities, and any other form of compensation, who during any tax year, perform work or render services, in whole or in part in the City; and if more than one individual or shareholders of a professional corporation or members of an LLC, during any tax year performs work or renders services in whole or in part in the City, the term “Payroll Expense” means the total compensation paid including salaries, wages, bonuses, commissions, property issued or transferred in exchange for the performance of services (including but not limited to stock options), in addition to any compensation for services to owners of pass-through entities, and any other form of compensation for services, to all such individuals and shareholders of a professional corporation or members of an LLC. (b) Any person that grants a service provider a right to acquire an ownership interest in such person in exchange for the performance of services shall include in its payroll expense for the tax year in which such right is exercised an amount equal to the excess of (i) the fair market value of such ownership interest on the date such right is exercised over (ii) the price paid for such interest.

The tax rate? 1.5%. And remember that neither the federal government, nor California, tax gains on most employee stock options at all.

This is a complex situation, and it’s mostly theoretical at this point. We started hearing reports a few weeks ago that startups like Zynga and Twitter were worrying about it, but neither company wanted to comment. In fact, we got a lot of pressure not to write this article, lest we wake the city up to how much more it could be taxing out of its most over-performing corporate citizens. The Mayor’s office did not return our calls for comment either. So, it took us a few weeks to untangle exactly what the risk is.

Our main tour guide through the city’s tax law was John Duncan, the former general counsel for Slide, who is now in Google’s legal department. At first he, like most of the startup community, had never heard of any pending startup tax penalties. But the more he dug, the more he got to the bottom of it.

Here’s the run down:

San Francisco has long had a 1.5% payroll tax on any local businesses. No other Bay Area city does. Move your headquarters just a few miles over the city border– no tax. This alone is a big reason Twitter is considering moving to Brisbane.

San Francisco’s payroll tax says that “payroll” includes the value employees get for options, also known as the “spread,” says Duncan. “If I work for Slide, and I make $50,000 from my stock compensation, San Francisco says that is just as if Slide wrote me that check,” he says.

There are two kinds of options. Non-qualified options and ISOs. Typically, ISOs are the ones most employees get. In 2004, the Federal government examined this issue, and that it would not charge payroll tax on the ISO spread, although taxing the spread on non-quals was fine.

San Francisco has not clarified that ISOs are exempt from payroll tax. But so far they haven’t been taxed for one simple reason: Companies didn’t have to report the spread on employee’s ISOs to the IRS, so San Francisco never knew what that possibly taxable income was. That has just changed in January of this year, Duncan says. Now, companies have to file with the Feds to tell them how many people exercise ISOs, allowing the city of San Francisco the right and the information it needs to start charging payroll tax on this spread if it wants to.

Here’s how this would play out. Say a company like Twitter, valued at $3.4 billion in its last funding round, goes public at a $10 billion valuation and raises $100 million. There’s a good chance that most founder and employee equity would be tied up in ISOs, meaning as much as $3 billion – $6 billion of the $10 billion valuation could be tied up in stock that was originally an ISO. If it were half – $5 billion – then Twitter would get a tax bill from San Francisco for $75 million. 75% of the $100 million they just raised would be paid to San Francisco.

We’re making some assumptions here for the sake of illustration, but even if the percentage of ownership from stock options is lower, it’s still a hefty tax just for being to the North of the San Francisco Airport, West of the Bay Bridge or South of the Golden Gate. It’s a steep price to pay just for being located in the small seven-mile-by-seven-mile stretch of San Francisco proper. The second a company’s headquarters crosses those lines, that cost goes away. Imagine what Facebook — with a $70 billion secondary market valuation and growing– is saving in current and future payroll expense just by being in Palo Alto. Hundreds of millions of dollars.

Now, I know what you are thinking: Of course, San Francisco is not going to enforce this. Why would any city do anything to drive out thousands of jobs from the city? Why on earth would San Francisco even allow this threat to dangle? The answer lies in the city’s notoriously progressive politicians and voters who simply put have a history of hating millionaires. And billionaires? Well, they’re three zeros worse.

Check out this article by progressive local weekly The Bay Guardian if you don’t believe me. Residents are calling out Twitter for “corporate blackmail” and shirking its “social responsibility.” Wake up. This is a for-profit company with a fiduciary duty to shareholders. After all, if paying local payroll taxes were a well-agreed on “social responsibility,” why wouldn’t any other city in the Bay Area levy them? Why wouldn’t most other major cities in the United States levy them? San Francisco is a dangerous exception here, not the rule.

To wit: In November 2008, the city overwhelming approved something called Proposition Q, that would tax the money venture capitalists make from returns as payroll income, not capital gains. It’s unclear what the state of Proposition Q is. Duncan says there were some legal challenges to it, based on the proposition trying to do too many things at once and that it wasn’t well explained. He says it appears to be valid, but isn’t sure how enforced it is. Now, you can argue that those returns should be taxed as payroll and you can argue that the richest of San Franciscans should pay more taxes. Or you can be rational and realize, if proposition Q were enforced, any investor would shut their doors and move over the city line. Only unlike a multi-billion dollar startup, that VC fund doesn’t take thousands of jobs with it.

There are reasons for startups to be optimistic. This would still take a lot of work to enforce, and there’s always the chance the city values jobs more than its messianic Robin Hood fantasy. Indeed, there was an unprecedented exception put in place for payroll taxes on biotech companies in 2004 to encourage jobs. But it bears noting that the balance of power has shifted more towards progressives with San Francisco’s comparatively pro-business mayor Gavin Newsom becoming lieutenant governor of the state.

And frankly, city auditors may not even be thinking about going after ISOs. “I would be stunned if any company in San Francisco has been paying tax on ISOs or if San Francisco auditors have thought of the issue,” Duncan says. “But now that there’s this piece of paper, it makes it easier.” A city auditor making $40,000 a year is unlikely to have much sympathy for the hardships of a young multi-millionaire.

Another mitigating factor: It’s a bigger issue for companies aiming to go public, and that’s a small subset of startups. Typically the tax won’t amount to a cost-prohibitive amount in the case of an acquisition, and that cost could just be passed on to the acquiring company. No big deal. Is it possible that a company could move to San Mateo the year before an IPO? Yes. But could the city sue and allege that the value of those options was created in San Francisco? Yes, again. Because few other cities have local payroll taxes to begin with and the Federal government doesn’t subject these options to payroll taxes, there are almost no precedents here.

But among the reasons for optimism, don’t count capitalist common sense. San Francisco has a mixed record on supporting local businesses– to put it mildly. I’ve written before about how the city’s progressive government and neighborhood rabble rousers have a habit of supporting mom-and-pop retailers… until they’re successful enough to open a few more locations, then certain vocal residents can viciously turn on them.

That’s already unimaginable to most people. But penalizing entrepreneurs who create thousands of local jobs in just a few years? Well, if that starts to become enforced, this city will have really outdone itself. The financial industry has already largely left San Francisco; ditto publishing and media. In the late 1990s, most of Silicon Valley’s biggest technology hits including eBay, Yahoo, Google, Cisco, Oracle and Sun Microsystems were all headquartered outside San Francisco. The Web 2.0 movement has finally seen tech jobs come back, but they can just as easily leave again and few companies can create as many local jobs as quickly. This is not an idle threat: Because San Francisco is so out of step with its neighbors, moving a few miles solves the entire issue.

That the city would even toy with enforcing this is surely unfathomable to most cities. Billions have been spent by local governments world-wide trying to recreate what San Francisco is naturally blessed with, thanks to being close to the universities Silicon Valley’s first companies spun out of. Duncan notes that Slide saw a 1.5% payroll tax as an acceptable cost given lower commercial rents in San Francisco versus Palo Alto and greater access to talent. Similarly sky-high real estate and competition for talent hasn’t yet dented the Valley’s mojo– maybe a tax on ISOs won’t either. But when a move outside the seven-mile-by-seven-mile city alleviates the worry, it’s hard to argue the city doesn’t have more to gain by just reassuring companies taxing ISOs isn’t on the table. It might go down in history as the most staggering way to keep thousands of jobs without sacrificing a dime of revenue the city was anticipating. With America gripped in 9% unemployment, what city in its right mind wouldn’t make that trade?

The SF Weekly wrote a scathing cover story in 2009 that called San Francisco the worst run big city in the country, comparing it to a beautiful co-ed so spoiled by attention, she could act as obnoxious as she wanted without fear of reprisal. Twitter is sending a strong message that it doesn’t need the co-ed. It’s happy with the plainer girl next door. The threat has already gotten the city’s attention, and it’s deferring some of the next few years’ payroll tax for companies in certain high-vacancy stretches. Twitter has said that’s not good enough, and with this threat of ISO taxes hanging in the air– Twitter is right.

Hopefully for our startups and the city TechCrunch calls home, Twitter leaving will be enough of a dumping to wake San Francisco up before it enacts a disastrous policy for short term gain.