The number of laps are decided by taking a distance of 305 km and dividing it by the length of a lap (rounded up), which varies from racetrack to racetrack. (1)
quoting the official regulations (from 2011):
5.3
The distance of all races, from the start signal referred to in Article 38.9 to the chequered flag, shall be
equal to the least number of complete laps which exceed a distance of 305 km (Monaco 260km). However,
should two hours elapse before the scheduled race distance is completed, the leader will be shown the
chequered flag when he crosses the control line (the Line) at the end of the lap during which the two hour
period ended. However, should the race be suspended (see Article 41) the length of the suspension will be
added to this period.