What if I can make a profit for an assignment/project I did similar to "Google"? This is kind of like the google story. We are currently doing an project individually. The idea I came up with can be used as a website that can make profit. My question is, let's say I was able to make money with the code I am writing, since this is a university project that I will submit for marks, do they own a piece of that profit. I know that the Google guys had to pay about $300 million to Standford but it seemed to me like the "patent issue". And they dropped out so I really can't say much about their case. The facebook story is different.

So am I obligated to share the profit with the university or does this differ from institution to institution? After all, even if they take my code, since I wrote it, I can rewrite it with ease.

Edit: It's kind of like inventing something that can be sold or used as a service. Does the institution own a piece of it.
This cannot be answered in general.

It depends on the contract you have with the institution and the applicable law in your jurisdiction. It may depend on how you were funded as well.

I know of examples from both extremes: your university owns 100% and your university owns nothing, as well as everything in between. Some intermediate setting is probably more common, but, as I said, it depends.