Map from Google - San_Francisco

The climate of San Francisco can be defined "Mediterranean with cool summers", since both the winter temperatures and the rain pattern remind the Mediterranean climate, but the summer is unusually cool, due to the cold current that flows along the coast of California, and mists that form in the Bay of San Francisco, which in summer functions as a natural air conditioner for the city and the surrounding areas.
Here are the average temperatures.
San Francisco average temperatures
San Francisco J F M A M J J A S O N D
Min (°C) 5 6 7 8 10 11 12 12 12 10 8 6
Max (°C) 13 15 16 18 19 21 22 22 23 21 18 14

However, in the area there are different microclimates, which must be kept in mind by those who wish to move outside of the city proper (for example, to visit the national park of Yosemite): in general, away from the sea, the climate becomes more continental, a bit colder in winter and much warmer in summer.
Rainfall is not abundant, since it amounts to about 485 millimetres per year, but the period from November to March is quite rainy; in April and October there is little rain, while from June to September the rains are rare and sporadic.
Here is the average precipitation.
Average precipitation San Francisco
San Francisco J F M A M J J A S O N D Year
Prec. (mm) 100 90 70 35 15 3 0 0 5 20 40 105 483
Days 8 8 7 4 2 1 0 0 1 3 5 8 47

Winter, from December to mid-March, is mild and quite rainy. There are, however, sunny and dry periods, sometimes long. Very cold days are rare: at most the night temperature can approach freezing, and only on colder days it remains about 8/10 °C. But east of the city, in the Sacramento Valley, and more rarely also to the north and south of the bay, there may be night frosts.
Every so often, fog can form in the city, while this phenomenon is more common in the Sacramento Valley.

Spring, from mid-March to May, is cool or slightly cold at night, while days become gradually milder, and sometimes pleasantly warm, but with a moderate breeze in the afternoon that lowers the temperature. The rains become increasingly more rare.

Summer, from June to September, is cool, and it is usually foggy in the morning and sunny in the afternoon, with a cool breeze blowing from the sea. September, albeit slightly, is the warmest month. The foggiest districts (and windiest in the afternoon) are the westernmost ones (see Sunset District). The rains are rare, especially in July and August, when basically it never rains.
Daytime temperatures from June to September range from 17/19 °C in the towns on the Pacific coast (see Half Moon Bay) and the western districts of San Francisco, to 21/23 °C in the eastern districts, to 22/24 °C in Oakland and Richmond, on the other side of the bay, to 25/26 °C in the towns on the south shore of the bay (Palo Alto, Mountain View), and up to 28 °C in San Jose, just south of the bay.
Beware, though: it's sufficient to move to the east, in the Sacramento Valley (see Sacramento, Stockton, Modesto), to find very high daytime temperatures, usually about 33/35 °C, and sometimes even above 40 °C.
In the following map we can see the average maximum temperatures of August, which shows the significant differences that occur in the area. The city of San Francisco is indicated by a red pentagon.

Average maximum temperatures in the San Francisco area in August

Every so often, however, hot air from the desert can come to San Francisco, so that the temperature can touch 35/38 °C, from May to October. But these periods of hot weather are very rare (so that they can even not occur for a whole year), do not last long (just one or two days), and the heat is felt only during the day, because in the afternoon or evening cool air returns, brought by the sea breeze. For example, in the 14th of June, 2000 the temperature touched 40.6 °C, but the minimum temperature of the previous night had been 13 °C, and that of the next night was only 16 °C.

Autumn, in October and November, is initially mild, and gradually becomes cooler and rainier. Usually at night it begins to get a little cold from late October.

The amount of sunshine in San Francisco is sufficient in winter, when there is no shortage of sunny days, alternating however with cloudy periods, is very good in spring, when sunny weather prevails, and it's still very good in summer, at least in the afternoon, while in the morning there are frequent fogs and mists.

San Francisco

Because of the cold current, the sea is cold all year round, and its temperature remains stable throughout the year, since it ranges from 12 °C in the period from January to June, to 14 °C in the period from August to November.
Here are the average sea temperatures.
Sea temperature San Francisco
San Francisco J F M A M J J A S O N D
Sea (°C) 12 12 12 12 12 12 13 14 14 14 14 13

When to go

The best time to visit San Francisco is summer, from June to September, being the driest and warmest. You should, however, take into account cool temperatures, and sometimes even a little cold, at night and in the early morning, and morning mists, so it's better to bring a jacket and a sweater. Even the months of April, May and October, although they have a greater chance of rain, have usually a good weather, being mild and sunny. However, in the latter months it can be cold at night, especially in April, and in addition in spring the afternoon breezes can be intense.