Measure right: your new window fits inside the jamb of the old one. Measure the window's width at the top, bottom and middle. Measure length the same way. Check to see if the window's square---the diagonal measurements should be equal. Use the smallest length and width measurements to order your new sashes or window.
Use a sash kit for sash replacements in a double-hung frame. Remove the "stops"---the trim pieces that hold sashes---inside stop first. Remove one sash cord and tie it so the counterweight doesn't crash down into the wall, then the cord on other side. Remove the next "parting" stop and remove the sash cords from the second sash. Once the sashes are set aside, untie the knots and gently drop the counterweights into the walls. Then remove the pulley fixtures in the window jambs. Stuff or spray insulation into the pulley holes to close and insulate the counterweight cavity. Attach vinyl jamb liners with rust-resistant screws on each side of the window, and add a new wood parting stop on the head jamb. Pull the catches down on the outer sash track of the jamb liner, and load the outer sash. Repeat with the inner sash, and finish by replacing with inside stops on side and head jambs.
Remove the sashes, stops and trim around the inside if you're installing a replacement window. Remove exterior trim around the window. Check the sill for any damage---while the window's out is the best time to fix it. If your replacement window has a flange around the outside face, remove siding, caulking or other covering on the house sheathing so you can set it flush on the outer surface of the house.
Remove any wood fill if you won't need it. If the fill stays, square it using a carpenter's level and shims so the new window has a square frame. Check the jamb and sill for rot or other decay, and make repair or replace the decayed sections with epoxy. If the new window is simply an insert, it can be installed from the inside by tilting it in from the bottom. If it has a flange, tack it up from the exterior of the house with roughing nails.
Insert shims between the frame and the jamb from the inside to hold the new window frame square. Drive finish nails or screws through the shims around the window or through the insert frame to permanently attach the window to the jamb. Caulk around the frame, and use tar paper or self-adhesive sealer tape to form a moisture barrier all the way around the new window on the house's exterior. Replace any siding or other cover and reinstall exterior trim, caulking around the edges to finish. Inside, replace the sash stops, trim the shims with a small hand saw or utility knife and replace the inner trim on the window.