If you're working a regular job, you are almost always paid by the hour. Freelance work is sometimes paid by the hour, but more often the client will want you to bid a fixed price for the entire project: a 'contract price'. And even if it is paid by the hour, the hourly rate isn't generally a pre-determined constant - you will have to get in there and negotiate the hourly rate you deserve.
So how does one estimate a fair bid for a contract? Lets take a look at some of the most important factors to consider:
Time
The first factors to consider are how long the project will take to complete, and when the client wants it to be completed by. If the project is going to take a month, and the client wants results in a week, you probably don't want to touch this. If it looks like a week's work, and the client is expecting it to take 6 months, then you may be badly underestimating the amount of work.
How do you estimate how long a project will take? That comes down to practice and experience. You have worked in your field, you know roughly how long it takes you to complete each type of task - so you look at the project, break it down into its component parts, figure out how long each will take, and put it all together again. Is this difficult? Yes. Will you make mistakes? Yes. But over time you'll learn, and we will get to dealing with mistakes in a moment.
Expenses
The next factor is direct expenses. These are the expenses incurred directly by the job: do you need to buy new tools/computer/software in order to complete the job? Will you need to buy books or training? Will you need to travel as part of the job, or commute to the client's offices? All of this should be pretty straightforward to determine, and the prices for all of it should be easy to figure out - just add it all up.
After that comes living expenses, and these are a little more tricky: rent, utilities, cell phone bills, daily transport costs, food, entertainment... I am assuming you have a fairly good idea of your own cost of living, but if not, you need to figure this all out soonest. Once you have a good idea of your cost of living, multiply it by your time estimate, and add it to the rest of your expenses.
Taxes
So you have your expenses, and those form your bottom line: if you want to complete the job and keep a roof over your head, you have to make at least that much. But wait... The federal government wants a cut. And then there are state taxes. And social security. And don't forget health insurance - unless you already have a full-time job in addition to your freelance work, you'll need to pay for your own.
So you need to calculate all this up as well, and add it to your expenses. You probably already known your health insurance premiums, and there are tax and social security calculators on the internet, so this shouldn't present much in the way of difficulties.
Profit margin
Unless you are truly desperate (and there will be times when you are desperate), you don't want to be just barely managing to pay the bills. So we need to build some profit into this estimate. Ideally, you want to be making 30% profit or more, and obviously, the higher the better as long as the market will bear (apart from ethical concerns if you're just ripping off the client).
Risk management
So you have your bottom line, you've built in a tidy little profit, but there is still the matter of risk - and there are really two issues at play here. The first is estimation error: your time estimate may not be perfect, or the project may just hit unexpected snags and expenses. And the second is part and parcel of the very nature of free lancing: this isn't a regular job, so once the contract is over you are once again unemployed. This means that you need to account not only for living expenses during the contract, but also for living expenses while you search for your next contract. If you are lucky, you might have another contract lined up by the time you finish this one, but nothing in life is guaranteed.
So you have to build in a certain 'buffer' to absorb these risks. A common rule of thumb is to double your estimate, others go with 1.5x, but in the end this is a judgement call, based on your evaluation of risk. And also on your evaluation of how high you can actually bid, which brings us to...
Client expectations
At this point you hopefully have a very good idea of how much money you need to make for this contract to be worthwhile to you. So we reach what is perhaps the trickiest part of the entire process: judging how much the client is willing to pay. This is largely subjective, but it involves taking a good look at the client: does the client actually have a lot of money? Are they miserly with the money they have? Have they already budgeted a small/large amount for this project?
And very importantly: are they soliciting bids from other freelancers on this project, with which you need to compete? If you are the only person they have asked for a quote, then it often behooves you to pitch your quote a little high - you'll have a chance to negotiate the final price. But if you are bidding against other people, then you will rarely (if ever) have a chance to submit a later counter-bid.
And that's pretty much the gist of it - get out there and start estimating. I guarantee you'll make mistakes, maybe take a loss on a few projects, but if you develop the knack for it, it all evens out in the end.
*A final word: subcontracting
If someone hires me to develop a website, I'm fine on the technical end of things, but I am no artist. So I'll need to hire a graphic designer to work with me for at least a portion of the project. This is tricky: you need to factor in all the same considerations for the artist that you do for yourself - the only saving grace being that you are absorbing most of the risk, which makes their calculation simpler. My best advice is to find your subcontractor early, and communicate with them on the bidding process. They will have a better idea than you about their own time estimates and expenses.
Source