When Google shut down its Chinese search engine in 2010, it gave up access to an enormous market. There are more than twice as many people on the Internet in China as there are residents in the U.S., and the number of Chinese Internet users is growing at a rate that far surpasses that of any other country. Google has plans to return to China in the near future, but why did it turn away from the country for so long?

Censorship is why. Google effectively shut down its Chinese operations after it discovered a cyberattack from within the country that targeted it and dozens of other companies. And while investigating the attack, Google found that the Gmail accounts of a number of Chinese human-rights activists had been hacked.

Google had set up shop in China four years before the breach, offering a version of its services that conformed to the government’s oppressive censorship policies. At the time, Google officials said they’d decided that the most ethical option was to offer some services—albeit restricted by China’s censors—to the enormous Chinese market, rather than leave millions of Internet users with limited access to information.

But the 2010 attacks prompted the company to reverse course. Instead of complying with government requests to filter its search results, Google directed all of its Chinese traffic to the uncensored Hong Kong version of its search engine, a move that left the company vulnerable to being completely shut down in China. Indeed, Google’s services became inaccessible to most Chinese users within months.

Google’s move to pull the plug in China is an extreme example of the kinds of decisions Internet companies operating abroad are often up against: If they want to do business, they have to abide by local laws, which can include restrictions on speech. And since the United States has some of the most permissive freedom-of-speech laws in the world, American companies must adapt in order to do business even in parts of the world that are culturally very similar to the U.S.

Western European countries, which receive top marks from Freedom House for online openness, are far less tolerant than the U.S. of hateful speech and images. In Germany, where distributing swastikas is considered hate speech and is illegal, regulators recently investigated a complaint that Facebook was not adequately enforcing national hate-speech law. But it’s inconceivable that Facebook would close down its service in Germany just because the government asks for more censorship than the First Amendment would permit.

In countries with more repressive governments, companies routinely receive requests to take down a much wider range of content that violates local laws. In Russia, for example, speaking ill of public officials can lead to costly libel suits; just across the Black Sea, “insulting Turkishness” is punishable by fines and jail time.

Lee Rowland, a senior staff attorney at the American Civil Liberties Union, says companies should generally submit to governments’ requests for censorship, if it means they can keep delivering their services. But when they take down content from their platform, Rowland says, the company must be transparent.

“If these companies do whatever they’re capable of doing to publicize that their content is being screened, monitored, and sometimes censored by governments, I think there’s a really good argument that maintaining a social-media presence is inherently a liberalizing force,” Rowland said.

To that end, Google, Facebook, and Twitter all publish a detailed annual transparency report, where they show the number and type of content-takedown or user-information requests they received, and the number they complied with, from each country where they operate. The companies also lay out their rationale for dealing with these requests: Facebook, for example, says it checks every incoming request for “legal sufficiency” and “reject[s] or require[s] greater specificity on requests that are overly broad or vague.” But even the most thorough transparency report can be difficult to access in the countries where the reported censorship is taking place.

Rebecca MacKinnon, a prominent Internet-privacy advocate at New America, says companies should start thinking about how they will deal with free-speech issues even before they start doing business in a repressive state. “It’s about anticipating in advance what positions you’re going to be put in, and deciding in advance whether that’s an acceptable position to be in,” MacKinnon said. Many companies undergo a “human-rights impact assessment” before they expand to a new market with potential censorship pitfalls.

The calculus that goes into making decisions about free speech abroad is complicated. But there are few things that companies can do to push back against censorship-happy governments without losing access to an entire country.

Companies can set up stringent review processes for legal takedown requests. A stringent review can make sure governments aren’t taking advantage of Internet companies to censor content outside the bounds of the law, and thorough reporting and transparent policies can spur local activism to change repressive laws.

Twitter is an interesting test case. As with any company, its tolerance for complying with government requests can be gleaned from its actions. Twitter’s transparency report shows a sharp rise in takedown requests in 2015, driven in large part by a high volume of requests from Turkey and Russia; the company continues to operate in both of those countries.

In Iran, however, where Twitter has been blocked for more than five years, Twitter has made changes to accommodate Iranian users that are able to circumvent their government’s Internet filters. The company recently began allowing users with Iranian phone numbers to activate two-factor authentication, a login option which can protect accounts from being hacked. Rowland called Twitter’s actions in Iran the “ethical high-water mark for resisting government attempts to censor access to content.”

(A Twitter spokesperson declined to comment on the company’s legal and business decision-making, and spokespeople for Google and Facebook were not available to comment on this story.)

When deciding how to deal with censorship abroad, companies aren’t going at it alone. The Global Network Initiative, a privacy and digital human-rights organization, provides a roadmap for companies navigating business in repressive legal environments. GNI members represent for-profit companies—including Google and Facebook—investors, and nonprofit and academic organizations.

Google Executive Chairman Eric Schmidt speaks at the Chinese University of Hong Kong in 2013. (Bobby Yip / Reuters)

MacKinnon, who was a founding member of GNI and sits on its board, says the organization provides a space for companies who are up against tough choices to confer with other members, academics, and privacy advocates, in order to make informed decisions. But she says most companies are too preoccupied chasing short-term profits to put too much time and energy into implementing long-term free-speech protections. “GNI has at least put a framework in place that’s preventing things from being much worse than they’d otherwise be,” MacKinnon said.

Companies that do business abroad—even just in Europe—are dealing with an increasing number of government requests for content takedowns every year. Europe’s two-year old “right to be forgotten,” a European Union decision that allows citizens to ask Google to remove links to misleading, inaccurate, or irrelevant information about them, has opened a whole new category of content takedown requests. And growing worry that terrorist groups like the Islamic State are using social platforms to recruit and spread propaganda means that more governments are on the lookout for content that promotes terrorism, which typically violates platforms’ terms of service.

But while terms-of-service violations can result in bans and content takedowns, most Internet companies don’t report them in their transparency reports. This is a problem, says Rowland, because a government that’s particularly active in flagging terms-violating content for removal is essentially engaging in a different form of censorship.

The United Kingdom, for example, has taken special advantage of flagging tools, and at least one counter-terrorism unit in the U.K. government has been granted “super-flagger” status to request YouTube video takedowns, allowing it to flag violations en masse.

One reason some companies don’t report takedowns of content that violates their terms of service is because they can’t tell which requests come from governments. A spokesman for Twitter said governments are required to use the same mechanism for flagging tweets, photos, and accounts as the general public must use. The spokesperson said requests for takedowns based on terms-of-service violations are “very rare.”

Even as requests for takedowns increase every year, companies are engaging more and more with the governments that issue them. Take China: Google is hiring for dozens of positions there as it prepares its reentry, and is working toward an agreement to offer an app store for Android devices that would only include government-approved apps. In Pakistan, Google launched a localized version of YouTube last week that will adhere to local law, in a bid to get the government to lift a ban on the service.

These expansions will allow Google access to a large number of Internet users, delivering them more information, and at the same time bolstering the company’s bottom line. But for the millions of Internet users in China, Pakistan, and other places where censorship is the norm, the tradeoff for getting to use new services remains the same: Easily accessible information comes at the cost of continued government control, filtered through American Internet companies.