Usually (but not always), a network pays the production studios to make the show.Lot of money comes in to the network or station from advertising dollars. In some cases, they don't pay much if anything, and instead share advertising profit with the show's producers. Ratings measure how many people are watching. read more
TV shows are rented to the network, and if the network makes their money back through advertising revenue, they buy more seasons of the show. There's no way either a network would give away more money than they have to or that the shows would be given away for nothing but the promise of future advertising revenue. read more
With all that said, the biggest way a show makes money is in SYNDICATION. When a program is deemed successful, it is shopped around to the networks and or TV stations individually, and the rights to air reruns are sold. read more