If you are building a house or just installing new flooring in an old house, you must have a level subfloor to install a finish floor on. The subfloor must be flat within 3/16 inch within an 8-foot radius. If it is not level within that tolerance, you will have problems with your finish floor, no matter if it is carpet, wood, laminate or vinyl.
Step One
Check to see how far out of level your floor is. It may be that you can use some floor patch compound in a few places, sand it smooth and install your new floor with success.
Step Two
Sand it and level it with a sander. If you have at least a 3/4-inch subfloor and are not radically out of level, you can sand down the high spots to get the floor prepped for a finish floor.
Step Three
Remove the existing subfloor and replace it if you are way out of level. Usually a subfloor is out of level because the joists under it are not level. If you find floor joists that are cracking or crowned, you can cripple new joists on the existing ones. That may be the easiest way to get a level 3/4-inch subfloor. You will need a 4-foot level to get the joists level. A pneumatic nailer would make the job easier to attach the sister joists. Be sure you do not raise the level of the subfloor above where it was when you add the sister joists. You may have to sand or plane the existing joists. If you must raise the level of the joists, simply use 1/2-inch plywood for your new subfloor.
Step Four
Consider these caveats to leveling a floor. It seems easy to use a self-leveling patch: you pour it on, let it level and then put a new floor on. However, if it is concrete-based, it will crack when fasteners are driven into the patch. You can glue down new flooring, but not nail or screw it down safely. No matter how you do it, level your subfloor before you install a finish floor. You will have a bad flooring job if you don't.