Why stars streak
The stars appear to move across the sky because the Earth is rotating. A short exposure freezes them as points of light. A long exposure lets them travel, so each star records as a line. This is useful for star trail images, but most people want sharp stars, so the question is how long they can expose before the trails appear.
The 500 rule as a rough guide
A common starting point is the 500 rule. Divide 500 by the focal length of your lens. The result is an approximate maximum exposure time in seconds before stars start to trail on a full-frame camera. For example, a 25mm lens gives about 20 seconds, and a 50mm lens gives about 10 seconds.
The rule is only a guide. Stars near the celestial pole move more slowly than stars near the horizon, and sensor resolution and personal tolerance for trailing also matter. Use the number as a first estimate, then check your images at full size.
Crop sensors and newer sensors
On a camera with a smaller sensor than full frame, divide 500 by the crop factor before you divide by the focal length. This shortens the maximum time. Some photographers use a more detailed formula that also accounts for the pixel size of the sensor. Either approach gives a starting point, so test to see which works for your camera.
Setup: tripod, wide lens and aperture
A tripod keeps the frame steady across a long exposure. A wide lens shows more of the sky and lets you use a slightly longer exposure before the stars trail. A wide aperture, such as f/2.8 or wider if your lens allows it, lets more light reach the sensor so you can use a shorter exposure. Focus is important too. Set focus manually, often to infinity, and check it on a bright star or a distant light.
ISO and noise
A higher ISO brightens the stars, but it also raises noise. Start at a moderate ISO, then check the results on screen. Raising the ISO can let you shorten the exposure, which reduces trailing, so find the balance that gives you a clean image.
Bulb and timed exposures
For longer exposures, use a remote release. Many cameras offer timed speeds for shorter exposures, such as 15 or 30 seconds, and bulb mode for longer ones. Shooting a series of exposures, then combining them later, is another approach used by many night photographers. This is a more advanced technique, and it needs software and careful planning.
Test and adjust
Shoot a few frames at different times, starting near the 500 rule limit. Check each frame at full size for trailing and noise. Keep the setting that gives you clean stars with enough light in the scene. The best settings often differ between nights, so test again each time you go out.