A judge says San Francisco can keep about $13 million it has collected in short-term hotel room taxes from airlines whose crews stay at hotels during stopovers in the city.

The 14 percent "transient occupancy tax" is levied on hotel bills for stays of less than 30 days and helps pay for city services to visitors. Major airlines - American, Asiana, Cathay Pacific, Japan, Korean, United, Mexicana and British Airways - argued that they should be exempt because their employees occupy one or more rooms in a hotel for months, even if no individual employee stays for 30 days and no single room is reserved for an airline for 30 days.

But Superior Court Judge Richard Kramer said this week that the city properly imposed the tax on the airlines and did not enact an illegal tax increase. His decision covers the period between 2004 and 2011 and allows San Francisco to retain about $13 million in taxes and interest, said Deputy City Attorney Peter Keith.

The case involves a 1961 city ordinance that provides an exemption from the hotel tax to anyone who occupies or has the right to occupy "any guest room in a hotel for at least 30 consecutive days."

In a November ruling, Kramer said the ordinance was unclear and could be interpreted in two ways - the airlines' view that "any guest room" includes all rooms in the hotel where one of their crew members was staying, or the city's view that it refers to one guest room reserved for one or more airline employees for 30 days.

But he said the issue was settled by regulations adopted in 2007 by San Francisco's treasurer and tax collector, Jose Cisneros, that endorsed the city's interpretation and served the purpose of the tax ordinance.

"The airline personnel who stay in the rooms in fact come and go and are candidates to utilize services and facilities which are paid for by San Francisco taxpayers," Kramer wrote.

The airlines then argued that the 2007 regulations imposed a new tax without the public vote required by Proposition 218, a 1996 initiative. They noted that the city had frequently exempted airline employees from the hotel tax until a 2006 ruling by another judge led to Cisneros' regulations.

But Kramer said Tuesday that San Francisco had a varying and uncertain enforcement policy on the meaning of its tax ordinance until the 2007 regulations, which did not increase a previous tax but merely clarified an existing tax law.

The airlines could appeal the ruling. Their lawyer was unavailable for comment.