How to Install Molding
To install molding, start by cutting the pieces to the right size. Next, locate and mark studs as it's best to nail molding into a support structure. When placing the molding, first glue the edges that make contact with the wall or ceiling, then nail the molding into the stud. If you need to fit your molding around corners, cut 2 pieces of molding that will fit between the last board end and the corner. Make sure to miter the ends of both corner pieces at a 45 degree angle, with the long point on the back side where the molding touches the wall.
Cut the pieces to the right size. Make sure all of your pieces are cut to the correct size. Following sections will give specific advice on how to do that if you haven't already. Locate and mark your studs. It's best to nail molding into a stud (the internal, wooden support structure in your walls). Find and mark your studs using a stud finder or other alternative method. Glue the edges. When placing molding, you want to first glue the edges that will be making contact with the wall or ceiling. Don't use too much glue or get it too close to the edge, as this can cause seepage. Place the piece. Once you've added your glue, put the piece in places and adjust it until it fits snugly. Marking where on the wall the piece needs to line up, in pencil, can help a lot here. Use a wall laser-level if your ceiling is uneven. You can use a box cutter or other appropriate tool to shave a bit off the top of your molding to accommodate dips in the ceiling. If the piece is long, up high, and you don't have someone to give you a hand, just place a nail in the wall at the line where you know the bottom of the molding will be, roughly 1-2' from the end. You can patch this later. Nail it in place. With the molding fit into place, put a nail (add the thickness of the molding plus the drywall and a 1/2" for the stud to get the nail length) through the molding into the stud closest to the end of the piece. A nail gun will make this much easier. Try to nail the molding in only at the studs or at frames (such as around a window or door), as nailing elsewhere can lead to accidentally hitting a pipe or wiring! Wait to nail in the last 1.5-2' of a piece until you've fit in the piece that goes next to it. This will help you fit the pieces together more snugly. Do finishing touches. Use a nail setter to push in nails which are tool exposed. Use wall patching paste or wood putty to fill and mask the holes from the nails. Use caulk around the gaps between the molding and the wall. Caulking is especially important around doors and windows, to help combat moisture issues. Use paint as necessary to hide repairs. Measure your piece. Measure the distance between the last board end and the corner. Cut a piece of molding to this length. Measure and cut pieces for both sides of the corner. Miter the ends. Miter the ends of both corner pieces at a 45° angle, with the long point on the back side, where the molding will touch the wall. This should allow the two corner pieces to fit together. The length on the backside should now be longer than the length on the front side. For inside corners, the back side of the molding should be equal to the length of the wall you need to cover, from the corner to the next piece of molding. Place the pieces. Add glue to the sides of the molding touching the wall or ceiling (being careful not to add too much) and then fit them into place. Make sure both pieces get a nice, smooth fit. Nail in place. Once they've been fit into place, nail the molding into the studs, alternating between the top and bottom of the molding. Make sure not to get too close to any edges, as this can cause cracking. Measure your piece. Measure the distance between the last board end and the corner. Add twice the thickness of molding plus an inch or two and cut a piece of molding to this length. Measure and cut pieces for both sides of the corner. Tip: Check the molding against the wall. Dry-fit the molding to the wall and mark the back of the molding as close as you can get to the corner. This may be a more helpful measurement than the one you took. Start with whatever measurement is longer, to be safe. Miter the ends. Miter the ends of both corner pieces at a 45° angle, with the long point on the front or facing side of the molding. This should allow the two corner pieces to fit together. The length on the front side should now be longer than the length on the back side. Place the pieces. Add glue to the sides of the molding touching the wall or ceiling (being careful not to add too much) and then fit them into place. Make sure both pieces get a nice, smooth fit. Nail in place. Once they've been fit into place, nail the molding into the studs, alternating between the top and bottom of the molding. Make sure not to get too close to any edges, as this can cause cracking. With outside corner molding, you should also nail through the end of one piece into the other, if it is thick enough. Do your math. Figure out what the measures of the angles will have to be for the pieces. Take the overall angle of the corner you need to turn (usually 90°)and divide it by the number of ends being used to make the turn (thus 45° for a normal corner). If you are using three pieces of molding to make the turn, you'll usually need to be cutting those at 22.5°. Measure, cut, and roughly place the two side pieces. Cut your side pieces with 22.5° angled ends, so that the shorter, inside point ends right where the wall begins to curve. Dry fit the pieces and mark where they end on the wall with a pencil. Measure the distance between them at the base. Measure the distance been them at their base. This will be your measurement for the transition piece. Cut your transition piece. Cut your transition piece with the 22.5° angles on each side, with the long points both on the outside, facing surface of the molding. Err on the side of making the piece to long. You can also cut it down further to get a good fit. Place your transition piece. Place all of the pieces and glue and nail them as normal. Alternatively, make a regular corner and fill the gap. If you don't like the look of a transitional piece, you can make a regular corner and simply plaster the gap that's formed. Install door molding. Door and window molding is essentially the same as wall molding, it simply places the boards in the other direction. Most of the same instructions apply. For doors, keep in mind that there are a number of ways to do the corners. You can miter them as discussed above, you can use decorative corner pieces, or you can construct a lintel. All of these options are likely easier than the mitered corners. Don't forget to accommodate doors. Make sure there will not be any overlap. Install window molding. Windows are much the same as doors. The main difference for installing molding on windows is that you must be careful of the window frame. Do not entirely overlap the window frame and make sure you are only hammering molding into the studs around the window. Install base trim. Doing base trim, or the molding at floor level, is mostly the same as installing it anywhere else on a wall. Just be sure to use thin blocks or skims to account for carpeting. You don't want to place the molding directly at the subfloor. Also, don't forget about shoe molding. It is installed exactly the same as wall molding and can make your floor look much cleaner and professional. Install chair or picture rails. Chair and picture rails are the same as wall molding. Just be sure to use a laser level and measure constantly to make sure you're keeping them straight. Use MDF instead of plywood for chair and picture rails since it's cheaper and smoother. Install shadow boxes. Shadow boxes are built much like picture frames. Make sure to lay everything out in pencil before you cut your pieces, try to make as many as possible the same size to save time, and make sure you hammer them in at the studs (to avoid hitting wires or pipes). For doing odd angles, such as for stairs, just remember the formula we discussed earlier: take the total angle that needs to be accomplished and divide it by 2 (for the two pieces making the turn). 
Cut the pieces to the right size. Locate and mark your studs. Glue the edges. Place the piece. Nail it in place. Do finishing touches. Measure your piece. Miter the ends. Place the pieces. Nail in place. Measure your piece. Miter the ends. Place the pieces. Nail in place. Do your math. Measure, cut, and roughly place the two side pieces. Measure the distance between them at the base. Cut your transition piece. Place your transition piece. Alternatively, make a regular corner and fill the gap. Install door molding. Install window molding. Install base trim. Install chair or picture rails. Install shadow boxes. 