Let's say you are in the market to buy your first home, but there's a small chance that I might be offered a job in a faraway location within the next several weeks, in which case all your plans will change. If you put in an offer on a house, how long do you have in which to get out of it without major legal or other hassles?
Your ability to withdraw from a home purchase depends on two things:
You are not "in contract" to buy a house until you (that's the plural "you" if buying as a couple) and the sellers have all signed your names to a purchase agreement. Getting to that point usually takes a few steps.
To get you to that point, in order to place an offer on a house, you will in all likelihood deliver a written offer to the seller, possibly on a standard form. That offer will likely contain an expiration date, so that if the seller doesn't act on it within a given amount of time, the offer dies by itself.
But let's assume that doesn't happen, and that you're placing an offer with a seller who would like nothing more than to sell you the house.
Just how detailed your offer document will be varies across the United States, and could impact the point at which you're in contract. In California, for example, the standard purchase offer is written in the form of a contract, so that the seller could sign it and boom, you'd be in contract to buy; though more often, the seller will come back with a counteroffer (also in the form of a full purchase agreement) hoping that the buyer will sign that amended version.
In New York, by contrast, the buyer delivers a much briefer statement of the terms being offered, and it's up to the seller to draft the full purchase agreement, which the buyer eventually signs off on.
Until both parties have come to an agreement on all the contract terms and actually signed the purchase agreement, neither of you are legally bound to anything, and you can withdraw your offer without any problem. You would simply have your real estate agent get in touch with the seller's agent, most likely orally at first, quickly followed up by a written confirmation.
After you are in contract, the situation changes. You are legally bound to go through with the sale, unless one of the contingencies (conditions) set forth in your purchase contract isn't met. The earnest money deposit that you likely put down to accompany your contract might be forfeited if you fail to go through with the deal for a reason not contemplated in the contract.
As a practical matter, most contract contingencies provide major "outs," assuming you included them rather than waiving them to make your offer more tempting to the seller. (In multiple bid situations, for instance, it's becoming increasingly common for offerors to waive the inspection contingency; and anyone with the cash to avoid needing a mortgage would likely waive the financing contingency).
But if you included all the usual contingencies in your contract, and, for example, your home financing doesn't come through, you could cancel the contract. Similarly, if you're not satisfied with the results of the home inspection (which is bound to turn up some defects) you can also call it quits. Talk to your real estate agent or lawyer about your exact rights under the contract, both before signing it and if it turns out that you need to cancel.
If you need to cancel the contract and can't justify it based on one of the contract contingencies, realize that many sellers will be reasonable and not insist on keeping your entire earnest money deposit; especially when it's clear that your reason for canceling isn't mere fickleness, but due to a major change in your circumstances. Again, your real estate agent or attorney is the best one to negotiate this.
For more information, see the Making an Offer on a House page of Nolo's website.