The internet has enabled like-minded people to communicate with each other no matter where in the world they are - and amazing things can happen when people get together in a spirit of co-operation. Linux is a superb example what a community can achieve. And all done in with wonderful open-handed generosity. <<< I'm sure there's a large element of that, but there are other motivations. Such as:
Publicity. You can pay for advertising space or you can give away your IP (Intellectual Property). The former proves you're good at guff; the latter shows what you can do. Most people treat adverts with considerable scepticism anyway, so who's to say which is money better spent?
Revenge. As in, "That's the last time I get shafted by (insert name here)". In my case, when MS updated from Win16 to Win32 and obsoleted all my code overnight.
Barter. You do this for me and I'll do that for you.
Necessity. Have you seen how much it costs to join the .NET game?
But whatever the motivation, the results are often better than commercially-driven equivalents. Someone once said
"All the world's best software was written by teams of two or less."
-- GT