Marvel has long wanted to put Spider-Man in its movies, but since Sony Pictures controlled the rights to the character since 1999, the web-slinger has been off limits. Making a crossover could have been costly, since Disney would have been expected to shell out millions. But the actual deal turns out to much cheaper — more like free.

Marvel Studios won’t pay Sony Pictures for the rights to put Spider-Man in “Captain America: Civil War,” the “Avengers” franchise or its other superhero films, as part of its new partnership with the studio, according to sources with knowledge of the deal. At the same time, Marvel won’t receive a cut of the box office for any of Sony’s films that feature Spider-Man. Sony won’t receive a percentage of the revenue Disney makes from Marvel’s films that have Spider-Man, either.

There may be some opportunities for Marvel to benefit financially from the Sony films, with payments tied to certain box office milestones. The financial relationship is likened by sources to the kind of compensation structure a producer would receive.

Marvel had originally wanted to buy back Spider-Man from Sony. But its resulting partnership, which was in the works since October, is just that — an arrangement that enables both Sony and Marvel to mutually benefit at the box office by having Spider-Man appear in their movies.

The deal actually benefits both sides significantly.

Sony needed to breathe life into its “Spider-Man” franchise; by lending its character to Marvel, it has a way to generate more exposure for its bigscreen hero. Doing so also creates some serious goodwill among Spider-Man fans, who have wanted to see the character become part of the Avengers.

Marvel now gets access to one of the comicbook company’s most popular characters — it already controlled the rights for TV, merchandise and other platforms, but the holy grail for Disney has lately been film, where it has been able to launch franchises that impact the bottom line of all of its various divisions.

Character crossovers across studio films are virtually unheard of and have been considered too cost prohibitive in the past. They’re so rare that Marvel and Fox cast different actors to play Quicksilver in “The Avengers: Age of Ultron” and “X-Men: Days of Future Past.”

But with Sony looking for a creative way to put a spotlight on its franchise, and Marvel so eager to get its hands on Spidey, Hollywood actually figured out a way to work together for once.

The next step for Sony, of course, is to recast Spider-Man. The studio is looking to go back to Spidey’s roots and put the character back in high school, which would require it to cast a younger actor, Variety has learned. Andrew Garfield is no longer playing the character.

The studio is still moving forward with the Spider-Man villain-centric “Sinister Six,” and “Venom” spinoff, as well as a film that features female characters in the “Spider-Man” universe. “The Amazing Spider-Man 3” has been cancelled. While Marvel’s Kevin Feige is involved with Sony’s new “Spider-Man” films, he is currently not expected to be creatively involved with the spinoffs, sources say.