Er... apologies for necromancy on this thread, but it is linked to from the main game mechanics section of CivFanatics so it probably ought to be corrected... and I'm pretty sure that it's incorrectly describing the modifier calculation. I also apologize in advance if this is a mistake on my part, either because I'm being stupid or because the actual code is different from what he posted in spoiler tags - I don't have the SDK, so I'm going by what's in detektyw's post.
Following the code, assuming all the default defines, here's how you determine espionage cost multiplier...
Start with 100.
Multiply by 0.8 if you have a trade route, then round down to the nearest integer.
If the city has your state religion, your religion is different from the target civs, and you have the holy city, multiply by 0.6, then round down.
Alternatively, if the city has your state religion, the target civ also does, and you have the holy city, multiply by 0.75, then round down.
Alternatively, if the city has your state religion, the target civ does not, and you do not have the holy city, multiply by 0.85, then round down.
Ignoring some miniscule rounding differences on culture ratios...
Multiply by (1 - (.5 * your culture) / (your culture + their culture)), then round down.
Multiply (100 + the city's espionage defense)/100, then round down. I'm not sure, but I assume that's the 50% defense for security bureau.
Multiply by the distance modifier, then round down (if the plot doesn't have a target, use the enemy capital as target).
Multiply by max(1.0 - 0.1*turns fortified, .5). If your spy has 5 full turns fortified, this is 0.5.
Multiply by (2x + y)/(x + 2y), where x is your espionage points and y is their espionage points. This is total espionage points generated for all time. It includes espionage points aimed at different targets, and espionage points already spent on missions. It also includes espionage from great spy missions. Really, I just tested all that because it seemed odd to me. Round down.
So let's take an example to demonstrate how different this is from the method given by Detektyw (whose work I really do admire, even if I think it is not quite correct in this case). Let's aim for a near-best case situation. Say the target civ isn't your religion, but the target city has your religion, and you have the holy city. Suppose it's under heavy culture-press - 50% your culture, 50% theirs. It doesn't have a Security Bureau. It's close to your capital - maybe 20% distance modifier. Your spy has been fortified for 5 or more turns. You've spent three times as much on espionage this game as they have.
Then, using the guide from page 1 of this thread... start with 100. Subtract 20 for trade route (80). Subtract 25 for holy city (55). Multiply by 0.75 for culture (41.25). Add 20 for distance (61.25). Subtract 50 for stationary spy (11.25). Add 71.4 for espionage ratios (82.7). So you pay 82.7% of base cost.
Using the procedure I just outlined... start with 100. Multiply by 0.8 for trade route (80). Multiply by 0.6 for religious modifiers (48). Multiply by 0.75 for culture (36). No security bureau. Multiply by 1.2 for distance (43.2) then round down (43). Multiply by 0.5 for stationary bonus (21.5) then round down (21). Multiply by 0.715 for espionage spending (15.015) then round down (15). So you pay 15% of the base cost. A bit of a difference.
So using this procedure (I believe the correct one, although if someone else who knows C++ wants to check feel free), what are the big points about espionage?
-The holy city bonus is great.
-It's nice to have the target city share your religion, but that only matters if the target civ does not share your religion.
-Aim to have a trade route to the city you aim at.
-The city you go for should have the best ratio of your culture : owner's culture possible. If someone conquers a city from you in a war, that's a great target for espionage! If you have 100 times the culture they do, you get a 49.5% discount on missions there; if you have just the same culture, that's 25%, and if you have no culture, no discount for you. This actually opens the possibility that if you have a large-ish empire but are badly behind in tech, you might want to let someone conquer one of your cities just so you can steal all their techs cheaply. You can always take it back 10 turns later with another war. Be sure to stockpile spies and espionage on them in advance though, as once they start accumulating culture there costs will rise.
-The city should not have a security bureau. This is a no-brainer.
-The city should be as close to your capital as possible. If you're running an espionage economy, you might even move your capital to your borders later in the game just to get that discount... although probably only if you're running state property as well.
-Your spy should have been fortified for at least 5 turns before you try the mission.
-The more espionage you've generated this game, the cheaper it is. The more espionage they've generated, the more expensive. So espionage-heavy games also will get cheaper espionage; if you don't build jails, don't build IA or SB, and never touch the espionage slider, you'll pay a lot more for each mission. This varies between 0.5x (if you've generated infinitely more espionage) and 2.0x (if they've generated infinitely more espionage).
This also opens up the possibility of a new use for a great artist (at least, I think it's new; maybe players have been using it and I just haven't heard?) - speeding "research" drastically early in the game. 1. Pile up espionage against an opponent who has techs you want. 2. Drop a bunch of spies in one of their border cities which was newly founded and is near your capital. 3. 5 turns later, use a great artist to swamp the culture in that city with your own culture. 4. Immediately use your spies to steal all their technologies. The city may flip shortly thereafter, so your time window may be limited.
This also indicates that spying for technology with good modifiers is a lot cheaper than indicated by the prior analysis. I'll go with detektyw's numbers for science city - 260%. But you really should have 250% for an espionage city, as you ought to be running nationhood. Sticking with his analysis for science, you've got a 442% boost to commerce spent on research (if it's for a tech everyone already has, etc. etc.). For espionage, however, it's quite possible (as I demonstrated) that you could get the modifiers down to 15%, or even less (5% costs is plausible if you micro carefully to set that exact situation up, and have been running a serious espionage economy for a long time). Assuming his steal-technology formula is accurate (lacking the SDK, I can't track down half the functions so I'll take it on faith), you pay 125% of the base cost of the tech as a base cost to steal it. So with a 15% modifier, you're looking at paying 18.8% of the tech's base cost in beakers as an espionage cost to steal it. That means one point of commerce becomes 2.5 points from modifiers in-city, becomes 13.3 beakers of base tech cost production from stealing techs... or over 3 times as rewarding as if you'd just put that commerce into research yourself. Of course, if you managed to get the multiplier down to 5%, you're getting 9 times as many beakers out of espionage as you would out of commerce.
Of course, there are the usual caveats with an espionage economy, but this does indicate that if you're smart about when and how you spend espionage points, the benefits can be greater. To me, the tricky part is that ideally you have a holy city for your state religion, the city you're stealing from has that religion, but the civ you're stealing from doesn't... which makes the diplomacy game very complicated because you're already getting negative diplo. points when your spies are caught. I'd be interested to hear how a more experienced player would tackle that sort of consideration for emperor+, or if they'd just swallow the much higher costs of adopting a common AI religion instead.
Edit: I was curious how effective culture-bombing a city before stealing techs would be, and it's a little disappointing. Apparently the target of steal technology isn't a city, even though a spy must be in a city to run it... so you get no bonus on that operation from culture-bombing, and presumably would get no bonus from running steal tech on a city which used to be yours and the enemy just took from you (except that it might be closer to your capital, so lower distance penalty).