As no one has written extensively about visas and the OP has glorified Berlin without saying how to legally become a resident and earn money, I'll try to do it (and tell you a nice little story in the process).

Short intro: I have lived in Germany for more than 15 years. I have learned the language and subsequently studied CompSci there, I love so many things about Germany, I have family and friends there, I still follow what's happening there through the media, I have worked there as a developer and consultant.

(All info is for non-EU citizens)

Working with tourist visa is impossible. Legally.

Obtaining the student visa (the same OP had/has) is fairly easy. And you can work with it. But only for an employer (so, no freelancing, no incorporating). And for 19 hrs/week maximum. If you work more, German IRS ("Finanzamt") will contact your employer and you both can get in trouble.

Obtaining other kinds of visas is much harder. You need both the staying visa ("Aufenthaltserlaubnis") from the Immigration Service ("Ausländerbehörde") and the work permit ("Arbeitserlaubnis") from the Employment Center ("Bundesagentur für Arbeit"). If there are no German and EU citizens available for the job, and you have the qualification that is in shortage, and your employer has proven all that to the Immigration Service (process that can take months - it's time and money consuming) and is willing to pay you at least €60.000 a year (which is quite a lot!) then, and only then you can get the work permit. Needless to say, finding an employer who's willing to go through that procedure isn't easy. Caveat: You are quite dependent on that employer afterwards.

More info (in German, try Google translate):http://migration-business.de/2011/09/hochqualifizierte-raus-...

Obtaining visa for incorporating a company is the hardest thing! There are two ways:

1. If you have had staying visa and work permit for more that five years you can apply for permanent residence ("Unbefristete Aufenthaltserlaubnis"). The procedure lasts three to six months and if you are (as German politicians like to say) "integrated" (you speak fluent German, know the country, have German friends, no criminal record, not a terrorist etc.) there is no major thing that'd hinder you to become permanent resident. With permanent residence you can incorporate whatever you want (sole proprietorship, a company).

2. This is a lesser known way: If your staying visa and work permit is "younger" than five years you can write a business plan. Immigration Service will pass it to the local Chamber of Commerce ("Handelskammer") and after the positive review they'll give a green light and Immigration Service will add to your visa that you are allowed to incorporate. That's how it should work. On paper. The real life is different.

As this is a lesser known way, I know only one guy who has tried it. Great credentials: Studied in Germany, flawless German, "integrated" (gosh, I hate that word), very competent. Worked for a year, and didn't want to wait for another four to be allowed to incorporate. Had a great idea. Wrote a great business plan. And went through limbo with it. In order to get to the positive outcome he, preemptively, has contacted and worked with the Chamber of Commerce guy who has worked on his case. That guy would return the business plan every week with new "potential problems" in it. My friend would improve it, send the new version, CoC guy would again find fault with his plan, and the game would start again. And go on for almost eight months.

To cut to the chase, my friend went to a high civil servant ("Oberstadtinspektor") with the local Immigration Service and what the civil servant has told him was revealing. His exact words were: "If I let you stay here, what should I do if, due to you business activity, a German business loses a contract and complains against us." My friend answered that he cannot rule out that such thing won't happen. But in that case, his company will still employ Germans and pay taxes in Germany - German state would still benefit from his venture. Otherwise, if he'd incorporate somewhere else, that scenario could still happen, but he wouldn't employ Germans and pay taxes in Germany. Civil servant answered "I've told you everything I can."

My friend, disappointed, returned to his home country realizing that such way of thinking was also the reason CoC guy behaved the way he behaved (in my friend's words "No German is willing to take responsibility for allowing ANY foreigner to stay in Germany"). He calls himself an "Economic Hitman" (yes, he's John Perkins fan :))): He now owns a tech company that employs 80 people, and uses his knowledge of the German culture, language, businesses to work exclusively with Germany. And to INTENTIONALLY make that scenario happen. And it has happened a few times (that he's aware of): German businesses were not taken, his was. His competitive advantage is, for one reason, the fact that his company is NOT in Germany. In his country labor is cheaper and he pays a lot less taxes than in Germany - giving him leverage over German companies.

The irony: Those (civil servants) who's mission is to to the best for the citizens and the state have failed miserably. And, on the top of that, have proven to have NO CLUE about economy as they do not realize that economy is NOT a zero-sum game.