If you want to write for a living, you should write for free. Hell, if you already do write for a living, you should write for free. And that free writing should be some of your best work.
Mary Shelley wrote on spec.
Unless you're already famous for something else, you'll write for free before you write for money. And if you try to make it your living, you might spend the rest of your life trying to make your paid writing look more like your free writing. Here's the writing you probably should do for free, and the writing you probably shouldn't.
Do This for Free
Write about stuff that interests you. One typical method is to start a blog; I got my first job (writing for the former Gawker Media site Valleywag) by writing about Gawker in university, at a site called Blogebrity that some guys had set up as a joke. (I was not the first or last person to get hired at Gawker by writing about Gawker.) A more recent example is Kate Wagner, who turned her blog McMansion Hell into a promising career as an architectural critic, writing (for pay) at sites such as Curbed and 99 Per cent Invisible.
You can write anything you want for yourself - that's often why it's such good stuff. No one's helping you tighten stuff up, but neither are they watering down your vision. Put in some swear words, go stream-of-consciousness, make jokes that no one will get. This work will probably be a mess, but you might achieve something great. Very few publications would have accepted a pitch for Kate Wagner's conspiracy-theory-chic critiques of ugly McMansions. But once she'd built herself a platform with McMansion Hell, everyone wanted in on it.
You can get artistic, or you can concentrate on a marketable idea. It'd be wise to choose something you actually care about, rather than chase money, but I won't pretend the latter never got anyone a book deal. But consider all the formats available - a group blog, a podcast, YouTube sketches, a basement theatre company. This is the right time to do weird crap that couldn't possibly make money, because once you're getting paid, it has to make money. Lifehacker writer Beth Skwarecki has written nine novels, never published a single one, and is very happy about it.
This year, I will write my tenth terrible novel. I do this every November; it's part of the NaNoWriMo tradition. I've never published these novels, but I grow as a writer and as a human being every time I write one. Let me tell you why it's worthwhile.
If you want a little more audience off the bat, contribute to small outlets. Some can't afford to pay at all; some can only pay small amounts. The pay isn't actually the point for you early on; the point is finding editors who can improve your work. Many of these editors are also just starting their careers, and will later reach out to you to write for more money; others are overqualified for their role and will give you priceless advice. I spent more time going over a humour piece for the indie blog The Toast (RIP) than I spent on pieces that paid 10 times as much, and I was so grateful for it. And that was nine years into my career.
Writing books often comes with a different form of free writing: The vast majority of novels are written on spec, then pitched to publishers. Most novelists have to write and pitch all their books this way. (Some get multi-book deals.) And most novelists have a book (or several) that never got published.
Same goes in TV and film. Screenwriters bang out a lot of unsellable films. Sometimes they write scripts purely as writing samples. Again, writing for free has its advantages here. This script for a 9/11 episode of Seinfeld could never actually get made, but it's actually funny and well-written, way beyond shock value. So it went viral, and two months later its author became a staff writer for Family Guy.
Don't Do This for Free
None of the above means that you shouldn't ask for what you deserve. Don't write free work if you don't enjoy it, and don't write free for just anyone who asks.
If you're writing for a well-known and well-financed publication, you should absolutely request payment. (Most well-known publications won't even ask for free work. But they might take months to pay you.)
Anyone who asks you to write for free should make their gratitude clear. They should also make it clear what they need from you, and offer you every opportunity to say no. If they act like you owe this to them, run away.
Once you do agree to write for free, you should be as reliable as you would be for money. If you can't, warn the publication about that ahead of time. Usually they will understand; they need money too, so they know how it feels. And if things fall apart, try to be as gracious and polite as possible. That doesn't mean overworking yourself, it just means trying to not leave anyone in the lurch. I've edited many writers who worked for free or for very low payment, and I tried to make them feel completely comfortable when they just couldn't complete something they'd pitched to me. That's the least I could do.
If and when your career takes off, you don't owe a publication your "loyalty". If you're getting too busy with paying work, tell them. This isn't indentured servitude. And if it's the publication that's blowing up, and you know they could start paying you, ask them to. There are a million other writers out there, but there are a million other publications too. Go to the ones that value you the most.