Shutting off your home's gas supply should be a rare event, prompted only by an emergency or the replacement of a gas-using appliance. In the latter case it's usually done by a contractor, but there are emergency situations in which the homeowner or tenant is the first line of defense.
Fortunately, most leaks are easy to detect by way of smell, thanks to the additive used in our natural gas supply. This is not the only indication - other signs can point to danger, as well. If you hear whistling or hissing coming from the vicinity of a gas line or gas appliance, or see debris nearby being blown around, it's imperative that you shut off the house gas supply at the meter and contact the supplier. Closing the valve is a simple procedure that could save lives and property.
Note: Many homes may have two gas shut off valves: one at the meter (called the street-side valve) and one on the main line feeding the house, before the first gas appliance (called the house-side valve). The latter is usually an easy-to-turn ball valve, intended for use when installing appliances. During an emergency, it's recommended that the street-side valve at the meter be closed.
As with many emergency preparedness tactics, you need to find the gas meter beforehand. They're usually of a decent size, so it shouldn't be too difficult to spot. Locations vary, but your best bet is to start the search outside: many are located somewhere on the perimeter of the home. If you don't find it there, the meter may be located under the house, or underground. Apartments and other multi-unit structures often have multiple meters together - ask your landlord where they're located and which is yours. Should you be unable to locate the meter, you can always give your utility a call.
A pipe will be coming out of the ground and into the meter. Somewhere on the inlet side of the meter, you'll find the shut off valve. Unlike your typical shut off valve, this one won't have a handle for you to turn - instead, there's what's called a "tang". When the tang is parallel to the pipe, the valve is open. You'll need an adjustable wrench - one at least 12 inches long - to turn it. A quarter-turn in any direction will close the valve (the tang will be perpendicular to the pipe).
It's a good idea to test out the valve before an emergency happens - older valves especially can become stuck. Use your wrench to slowly turn the tang about 45 degrees (this will not shut off the gas, just reduce flow) - if it moves, great! Restore full flow and rest easy. If it won't budge, don't force it - contact your provider, who will have it replaced.
Propane: If your home uses propane, it's easy to turn that supply off, as well: find the shutoff valve under the tank cap and turn the handwheel or knob in the indicated direction until the valve is closed. If the tank appears to be damaged, leave it be. Evacuate the area and call 911 immediately.
If a leak is suspected, immediately evacuate the house - don't flip any light switches, use a flashlight, open the refrigerator, turn anything off, or use the phone: any spark can ignite a room full of gas. Turn off the gas, and contact 911 or your provider from outside (or another location) so they can check for leaks.
Do not turn natural gas or propane back on (some valves actually have a safety reset feature that will prevent you from doing so) - err on the side of caution and let the professionals handle this as well as the relighting of pilot lights.
Helpful Hint: Most homes have individual shut off valves on each supply line (or "appliance connector") - if a leak is obviously coming from an appliance or its supply line, you can simply close that valve rather than dealing with the meter.
An increasing number of municipalities and insurance companies are requiring automatic gas shut off valves for new constructions and renovations. These valves can be activated by seismic activity, excessive flow through the line, or both. In the event of an earthquake or large leak, these valves will automatically shut off the gas. Be aware that in the event of an earthquake, your utility may not be able to restore gas service for weeks. If you have an automatic valve, be prepared and make a contingency plan.