But I thought a TV series only had a network and not a studio. What does the studio do? Pay for the season if the network is happy with the pilot?
Let's say we got The Flash. The network is The CW but who is the studio?
Well... (this is all just about the US TV biz) TV shows always have both a studio and a network. The studio owns the IP and licenses the show to the network. The network pays for around 60% of what an episode costs to make, I think. It's definitely well under 100%. So every season, the studio just loses more and more money making a show. Why?
Because if a show gets to syndication numbers (say, 88 episodes), then it can be sold to the syndication market for a ton of money, easily making up everything they lost up to that point, and more. It's so much money it makes up for the shows they made that never got to 88 episodes, and then some.
(When a show gets close and only needs one more season to get over the hump, but it doesn't do well for the network, sometimes the studio will cut the license fee for the final season just to get enough episodes.
Conversely, in Friends' 10th season, the studio didn't need to make any more episodes to make tons of money, but NBC was so desperate for reliable performers they ended up paying 100% of the show's cost for the final season.)
Now, that said, there used to be a rule that networks couldn't also own studios, but that rule was done away with and now corporate behemoths like Comcast (NBC-Universal) are both networks and studios. Fox has a network (and cable channels) and a studio.
The CW is a special case because it's actually owned as a partnership between CBS (which has its own network and cable channels separately) and Warner Brothers, which doesn't have a broadcast network any more, not after the WB and UPN had to merge. WB has cable channels of its own, and also like Comcast, has a parent company in the cable TV business too (Time-Warner Cable.)
Anyways, to answer your last question, The Flash is aired on the CW and owned by WB. So if the Flash gets to syndication, then those profits will go solely to WB. I think.
(also, not all shows even have networks. Some shows are "first-run syndication". The most successful recent one I can remember is Star Trek: TNG.)