A FEW CAUTIONS                        New window.

Safety. Until you need power on to make tests or try operating something, having the relevant circuit breakers off (or all breakers off) will put you out of harm's way.
Multiple Circuits. Expect to find more than one circuit present at some switch and outlet boxes, even single-gang boxes. Discovering this not only helps you be safer, it actually helps you understand what is what in those boxes. If more than one circuit is present in a box, their sets of neutrals should probably be kept apart from one another -- unless the two circuits arrive as a 3-wire cable (sharing a neutral), in which case the neutrals of both these circuits need to be wirenutted together.
Meters and Testers. Prefer logic and controlled experimentation, over testing with a meter. Holding a voltmeter or ohmmeter in your hands, you might imagine that they will tell you a lot. There are tests that can be done on a perfectly functioning home that neither you nor I would know how to interpret. How much less confidence should we put in testers while some connections are in doubt or missing! It is usually all we can handle to try out our existing lights and outlets as the acid test of whether we are on the right track.
Documenting. Unless your memory is a lot better than mine, prepare to write down details of how wires are now, what you plan to do to them, what you then actually do, and what the result is. You might even record your conclusions, in case they should be re-examined later.

IN GENERAL

Don't Panic. If you have caught an undoing of connections early (even several connections), you may need to apply only one or two principles to make your way back into working order. Use what is still intact as an asset, as clues for the few possibilities that need to be tried out now. To what extent have connections been changed? Removing a switch or light doesn't usually bother anything but the one light or set of lights involved. And removing a receptacle, though it very often affects the circuit from that point onward, does not tend to leave any problem once you put the new one in right. If this sort of replacement is all that has been done, it may be that Upgrading is all you need to read. Otherwise, read on. If a person has dug deeper -- in order to fix a circuit problem or trying to rewire something in the area -- then it may be harder to determine how to get things working properly again. Various wirenuts may have been removed without keeping careful track of which wires were together. Still, use what remains as it was, as help in the restoration process.
See the Clues. In general, wires that are together or seem to have been together (physically, not judging by color) can be considered as clues to their function and the function of other wires. One thing you might want to observe and write down before changing anything is: which wires and even ends-of-wires show signs of having been twisted together with others (they might go back together); a curled wire-end was probably attached under a switch or receptacle screw.
Notice Cables. Always remain aware of the cable a given wire is part of. The wires in each cable will be performing only one of the functions shown in the Cable-and-Wire Functions Chart. Each cable is coming from ("going to" means the same thing) another box somewhere. These other boxes can be opened, their wires perhaps tested, or their undisturbed connections simply read. The Cable and Box Chart may also help you limit the number of hook-up possibilities you might have to consider.

REVIEW COMMON HOOK-UP PRACTICE AND RULES

Switches. Not counting green terminals or wires, single-pole switches have 2 terminals, 3-way switches have 3, and 4-way switches have 4. For many dimmer and specialty switches, these terminals are in the form of wires that are part of the switch. Otherwise the terminals consist of screws and/or holes, which sometimes allow more than one wire to attach there. Some holes may hold onto the wires automatically (they theoretically release by a small screwdriver being inserted in a separate opening nearby). In other cases, holes only secure their wires when the screw is tightened down. A screw itself is designed to hold only one solid wire directly under it, curled clockwise.
Screws are generally brassy in color, but one of the terminals of a 3-way switch (the "common") is a different color, usually dark, and a 4-way switch has two brassy and two of another color. Many 3-way dimmer switches have wires instead of screw terminals. Any pair of 3-way switch screws or wires, that are the same color as each other are for a traveler pair to attach to. The third (odd-color) screw or wire connects to the common wire (that is, to a hot or the light-leg). See 3-ways.
A jumper is a short piece of wire within a box, going between two wirenuts or between two devices' terminals. It simply passes a function (hot, switched, or neutral) from the one place to the other. A pigtail does this too, but only goes from a wirenut to a device. I mention jumpers here to alert you that hot-wire jumpers that had been used originally between switches may have been discarded with the old switches. If so, some lights or other parts of the circuit will no longer work, and you would have to restore such hot connections in some way, not necessarily using jumpers (use pigtails).
Receptacles. What is said above about the terminals of switches is true of receptacles, except that the brassy screws on one side are for the hot or switched wires, and there are silvery screws on the other side for neutral wires. Be aware that each side of the common ("duplex") receptacle has removable metal pieces at these terminals, which are electrically connecting the top and bottom halves of the receptacle and their top and bottom terminals.
Lights. Lights that mount onto the ceiling or wall surface come with a white and a black wire (or sets of whites and blacks) to be attached by wirenuts to the appropriate neutrals and switched wires at the light box. Be aware that circuit wires unrelated to running the light may be present in the box. A recessed light has its connections in an integral junction box that is accessible from below, with a little trouble.
Ground Wires. I do not mention grounds (the bare or green wires) except here. Generally they all should be combined with each other and with added pieces that will terminate on each receptacle or switch that has a (green or bare) ground screw or wire. If you know some grounds in a box were not together before -- when things were working -- don't put them together yet; for the sake of your functionality problem, they should not matter. On the other hand, you may want to find if one of them is a reliable ground, in case you will be testing for voltage later on.
Wire Colors. Remember that non-white wires are not neutrals, and neutrals are white, but this does not mean every white wire is a neutral. In fact wires I am calling "white" on this page may already have been designated as non-neutrals by tape or ink, and doing this to non-neutral white wires would bring your wiring up to current Code. Still, for our purposes here, always notice which wires were white from the factory, regardless of their appearance now; these are what I am calling white. With all this said, it remains true that true neutrals are never to be switched, though they were sometimes in the 1920s or 1930s.
Position in a Box. The position of a cable in a box, from right to left, may correspond somewhat to which switch it relates to, but do not rely on this. The same holds for whether a cable comes into the box from above or below -- a ceiling light cable (leg) might tend to come in from above, but not always.

KNOW YOUR SITUATION

Realize What You Already Know. Review in your mind how the various switches, lights, and receptacles in the area had related to one another. Was a fan-light controlled by one or by two switches? How many total switches controlled each set of lights in the area? Consider whether some outlet might have been switched.
Look Behind the Scenes. In any box you are dealing with, loosen the switches, receptacles, or lights there (and at other boxes of the circuit, nearby or related by switching) enough to view how many cables of what sort (2-wire vs. 3-wire) show up at all these boxes.

READING WIRENUTS AT SWITCH BOXES It will be up to you to apply the principles of this tutorial to your situation, but the status of existing connections at a switch box may help you, as follows.

Setting up single-pole switches. If any white wires are wirenutted to other white wires (without other colors in those wirenuts), they are probably neutrals and in any case should be left as they are. Each black and each red (whose black mate is in a wirenut) that are not in a wirenut and whose white mate is wirenutted with two or more other whites, is probably to be switched and will attach to one terminal of a single-pole switch. Each black bundled in a wirenut but that does not "leave" the box in a cable, is probably to be a hot and each one will attach to the other terminal of single-pole switches.
Setting up some 3- and 4-way switches. If it is known that a box is to serve a 3-way switch; and there is a 3-wire cable entering the box, and its white wire is wirenutted to other wires and its black and red wire are not, then the black and red of such a cable are probably to be travelers and will attach to the same-color terminals of a 3-way switch (in either order). (If there are two such 3-wire cables that meet this description and their whites are wirenutted to each other only, they are probably for a 4-way, not 3-way, switch that will have black-red pairs attached, one pair to each same-color pair of terminals.) The common terminal of 3-way switches will receive either a light-leg black (or red) or a hot wire, which is often a black piece coming from a wirenut containing several blacks.
Setting up other 3-way switches. If the white wire of any 3-wire cable was not wirenutted to any other wires, and its black and red mates are likewise free, then these three should probably hook to the terminals of a 3-way switch. There are only three ways this would have to be tried, namely, with each wire taking a turn under the "common" screw. But duplicating the traveler colors used at the traveler terminals of the other switch of the 3-way system may work immediately.
Keeping obvious circuits apart. If there are two or more bundles of white wires in a box, and if none of the black mates of the whites-in-one-bundle are wirenutted to any black mates of whites-in-another-bundle, retain this isolation, treating these as if they are from different circuits.

START FROM SCRATCH?

Whether to Start Over. If a lot of connections have been undone, and the charts and diagrams above don't help you make heads or tails of things, it may be best to separate all the wires in the box and start from scratch. In general you would then want to see which wires bring hot and neutral (if any) into the box. You could then start experimenting with one new connection at a time, to discover what is affected elsewhere in the house and therefore what the likely function of that new wire is meant to be. Turning power off again at each step makes sense; since you don't know what your new connection will do, you don't a short circuit possibly blowing up in your face.
Experimenting. When putting a box's wires back together from scratch, it is usually easy to tell which one cable (or more, if more circuits are there), if any, brings power to the box (the incoming p-cable or f-cable) -- just test between its black and white with a light bulb or voltmeter. But, particularly at switch and light boxes, it is harder to find which cables (if any) are passing the circuit on (outgoing p-cables or f-cables). Even at outlets, the remaining cables aren't always outgoing; once in a while an h-cable may be there. So the only sure way to identify which cables should hook up their whites as neutrals and blacks as hots, will be to hook candidates up one at a time and see the effect this has on the rest of the circuit. If you unknowingly hook up an h-cable in this way, nothing new downstream will be enabled (and one light may run unswitchably or one switch may trip the circuit's breaker). (By the way, if a short is passed through a dimmer switch, sometimes this will hurt it, so for the sake of experimenting, if you can use a standard switch there temporarily, do so.)