To be a tad too blunt about it, five or ten years ago I managed a group doing a piece of Unix kernel code critical to the specialized computer systems my employer sells. Now I do that myself as a Linux open source project cooperating with other people in other companies from around the globe (Australia, France, China, Japan, India, Eastern Europe, ...)
For a tenth the cost my employer is getting several times better technology, and our customers much prefer not being locked into proprietary solutions.
That's one way, but not typical.
Here's a fact: Most companies that write software never sell it. The number is huge, something like 90%.
Most software is written in-house for in-house use. It never gets sold.
Since most businesses have the same basic needs, the process of writing software to run internal systems is extremely wasteful. Every company out there that writes a bit of software writes basically the same thing with a few things different for their particular business practices.
Off-the-shelf commercial software doesn't help. It's a one size fits none thing that generally you can't modify to meet your needs.
Enter Open Source software. One company writes it. They give away the source. Hundreds of other companies take it, improve it, and give away the source.
The original company (who was never going to make any money off of the software anyway) gets back a better and more useful product. So do all of the other companies that make changes and release their source.
Everyone ends up with a better, more useful product. No one is out any money. Everyone SAVES money because they don't all have to keep reinventing the wheel.
And that's how you make money off of Open Source. By saving money.