I am trying to teach myself how to play piano and while I know what a key signature is, I don't have a firm grasp on it. I have sheet music in the key of G major. There aren't any F's on that line, but there are some in the first space. Does this mean I play that as sharp too? Sorry if this is a very stupid question, but Google just confused me more.
This is correctly answered by @Pat Muchmore, but I wanted to elaborate a bit so you can find your own way to understand more about this notational device. I hope it helps.
The key signature is a fixed set of either sharps or flats that appear immediately after the clef at the beginning of each staff.
The set is fixed in the sense that they follow the circle of fifths. As the simplest example, we can have no signs (neither flats nor sharps) at all.
This could denote either a key of C-major (c d e f g a b c) or a-minor (a b c d e f g a). Let's forget for this moment about the minor scales, because there is some additional things in play there that are only confusing at this point.
So, lets assume no flats nor sharps denotes a key of C-major. One of the keys closest to C-major is G-major. G-major has one sharp, structurally changing the notes that would normally be f-natural into f-sharp: g a b c d e #f g.
(The sharp is denoted with # and it has the function of altering the note to which it applies to make the note sound one semitone higher than would be expected based on the line alone on which the note appears.)
There are two things to observe here:
If you compare the sequence of degrees in C major with the ones in G-major then we get:
degree: | 1 2 3 4 5 6 7 8 ========|============================================ C: | c d e f g a b c G: | g a b c d e f# g ========|============================================ interval| 2 2 1 2 2 2 1
The "interval" row illustrates the number of semi-tones between the degrees of each scale. So structurally changing the f to f# allows the same sequence or pattern (in terms of semitones) between the scale degrees, but based on G instead of C. This pattern is what defines the major scale, and by making this change we allow the pattern to center around a new fundamental point (c for C-major and G for G-major). This central point is the tonic of the key, and gives it its name. The tonic is also in a sense the most important or characteristic degree of the scale, and will almost without exception be prominently present at the beginning and the end of the piece (assuming it keeps its key, as most tonal music does).
You can go up another 5th from G to arrive at D. And in that case, we need a structural change of c natural into c# in order to produce the pattern that characterizes the major scale (in addition to the f# that was already in place for the key of G-major). So a piece in D-major will have two sharps at the beginning of the clef, the one at f# and at c#. You can keep repeating this process until all degrees are altered with a sharp, arriving at the key of C# major.
We can also go the other way around, and drop a 5th from C down to F. In order to reproduce the pattern of the major scale on F, it is not possible (or at least inconvenient to the point of being impossible) to denote that with sharps. So instead, flats are used.
(a flat is denoted with ♭ and makes the note sound one semitone lower than would be expected by the line alone on which the note appears)
If we add F to the table we get:
degree: | 1 2 3 4 5 6 7 8 ========|============================================ F: | f g a ♭b c d e f C: | c d e f g a b c G: | g a b c d e #f g ========|============================================ interval| 2 2 1 2 2 2 1
From F you can descend another fifth again to B♭, in which case we need another structural flat to make an e♭ from e in order to replicate the major scale pattern. And you can keep doing this until you arrive at a key with 7 flats, which would be C♭-major.
This is all nicely summarized in the "circle of fifths". Please see the wikipedia page: http://en.wikipedia.org/wiki/Circle_of_fifths
What may be potentially confusing at first is that the key signatures that are "generated" this way have a fixed way of assigning the signs to the lines of the staff. For instance, the first # appears on the top line of the treble staff, and on the second line of the bass staff. The second sharp appears on the nearest place for the c below the first sharp. And if were to ascend further along the circle of fifths, the 3rd sharp would be placed on the nearest g above the first sharp.
But regardless of the fact that these structural signs are assigned to one particular vertical position on the staff, they affect the notes in all other octaves too. So the first sharp on the top line of the treble key also affects any notes written between the bottom staff line and the one-but last staff line, altering the f's there too to f-sharp.
While it may seem counter-intuitive to elect only one specific line to denote the sign, it is actually really convenient since this allows you to tell the key by counting the number of signs. So 1 sharp is G, 2 sharps is D, 3 sharps is A and so on and so forth
Now so far this has all been about the structural signs (either flats or sharps) that appear near the clef at the beginning of each staff. Apart from those structural signs it regularly happens that a regular degree of the scale is altered. This is denoted by an accidental.
An accidental is a sign like a flat or a sharp, but it is not structural. It appears immediately before the note that is required to be altered. Once you see an accidental, it stays in effect for all notes on that exact line on which the accidental appears, and only until the end of the bar.
It is possible that the accidental is repeated later in the bar; however this is redundant and usually done to aid performance. So the function of the accidental doesn't "add up".
This is just the surface. There is additional info w/re to minor scales, and there are more signs than just flats and sharps. One you will regularly encounter is the natural sign, ♮ which serves to undo the effect of any preceding sign on that line. If the natural appears as accidental, then it is in effect until the next barline, or until the next other accidental on that staffline, whichever comes first.
However, I hope this helps a bit to get started.
The simple answer is that the # or b in the key signature tell us what key we're playing in. Each key has one or more # or b in it, except C maj. Your tune, in G maj., uses F# instead of F. Any F notes, anywhere on the piano, for that tune, will need to be played as F#. If for any reason the composer needs you to play a white F, he must tell you by cancelling the # sign with a natural. This only lasts for the bar, or until it's re-instated.
Trouble is, on a piano, the 'default' key is Cmaj., just using the white notes. All tunes will use only those notes, UNLESS they get changed with the key signature, generally, or extra #, b ,naturals, x or bb specifically, if you follow what I mean.
Let me take a crack at explaining the circle of fifths and key signatures here as well.
Every major scale has the same intervals: whole step, whole step, half step, whole step, whole step, whole step, half step. If you start on C, you get all these intervals using only white keys. If you start on other keys, you have to use some black keys to get this set of intervals.
Since there are 12 different notes between each octave, it follows that there are 12 major scales. They go in a pattern. Each time you go up a fifth (for example, C to G), you add a sharp, until you get to six. (Since there are 7 notes in a scale, you can't have more than 7 sharps.) Keep in mind that B to F# is a fifth, not B to F. B to F is actually a half step less than a fifth, called a "diminished fifth" or "tritone" (or in another time even "diabolus in musica", wherein lies a tale). The sharps that you add are themselves a fifth apart (a fifth up or fourth down, same thing, we just zigzag them so they'll all fit). Every sharp you add is sharping the 7th note of the new scale.
Now, once you get to six sharps, you change to six flats. Six sharps and six flats are actually the same scale, either F# major or Gb major. (It works out this way because the F# scale has an E# in it, which is the same key as F in the Gb scale, and Gb has a Cb in it, which is the same key as B in the F# scale. Sharps--and flats--can be white keys as well! Sharping a note just means playing the next one higher on the piano, even if it's white.) Gb has six flats, then, Db has five, and so on. Finally F has one flat, and C has none. So, you've come around in a circle, hence "circle of fifths."
If it has a F# on the first note, and if the second F doesn't have the accidental called "Natural", then you will have to play the same F with the #. If it has the accidental in the second F like showed up there, you will have to play the normal note of the F, not F#. But if there is a tie from the first F# to the next F then you will have to play the same F#