Cycling knee position is crucial for health and performance. Knees rely on internal fulcrums, levers, pulleys and balance to perform properly. If any of these factors are off, you might not notice it at first. But eventually, the poor alignment will cause your knee to wear, become sore or even fail. If your bike is adjusted properly, however, your knees should travel thousands and thousands of miles without any problems, growing stronger with each pedal stroke.
Your knees should never hurt during or after a ride unless you have other underlying medical conditions involving your knee. Cycling is sometimes used for knee injury therapy because it is low impact. It is also used by cross-country skiers in the off-season to build up knee stamina and power. If you have any doubt about the health of your knees, a checkup by a doctor can eliminate underlying causes of knee pain. If you don't have knee pain but your bike feels slow or hard to pedal, it may also be an indication that your knee positions are not optimized.
If your knees hurt when you ride, chances are that your seat position may be too far forward or too far back. When sitting on the seat with your feet on the pedals, the center of your knee should be directly over the pedal axle when the pedal is perfectly horizontal in the 3 o'clock position. You can check this by placing your bike in a trainer. Climb on the bike. Put your feet on the pedals and rotate one of them to the 3 o'clock position. Hang a weighted string from the center of your knee. It should intersect the pedal axle straight down the middle. If your knee is too far forward or too far back, slide the seat forward or back until you center your knee above the pedal axle. If you can't get this measurement right no matter how much you adjust the seat, the bike is the wrong size. Get a different bike.
At the bottom of the pedal stroke, your leg should never be completely straight. There should always be a slight bend in your knee at the bottom of the stroke. Ideally, the bend is between 5 and 10 degrees. If it is more than 10 degrees, raise the seat post up until the bend is within the range. If it is less than 5 degrees, lower the seat until the bend is within the range. This will also optimize your pedal stroke, making your bike respond better. One quick way to check this measurement: If you notice that you are bobbing from left to right as you ride, the seat is too high. If you feel that you are working too hard, unable to gain speed or climb hills properly, your seat may be too low.
If you are running pedals that clip to your shoe -- very common on modern bikes -- you can rely on the pedal to get your knee aligned left and right. Pedals that lock your knee into position keep your knees facing forward, but they also have a small amount of float. Pedals like this will typically allow your knees to angle about 6 degrees from side to side, which is within the recommended range of movement. This angle will be determined by your style of riding, and your legs will naturally find the best position within the 6-degree float. If your knees hurt because the pedal is forcing them into a proper position, it might take some getting accustomed to. If it continues to hurt, your knee may need medical attention.