Scales are the foundation that compositions are built upon. Generally when a composition is one key, it remains in that key for the duration of the compositions. However, there are some exceptions where the composition has a key change in the middle of the piece resulting in an emotional change for the listeners. The type of scale you base your composition is important and can change the overall ambiance your composition exudes.
The major scale is comprised of W-W-H-W-W-W-H where W is a whole step and H is half step. The W is a major second and the H is a minor second. If you look at the C scale above you will notice that there are no black keys between the E and the F where a half step takes place. Similarly, there is no black key between the B and the C, where the other half step takes place. These 7 notes comprise the C major scale. Keep in mind that the major scale can begin on any key. For example we can begin on the key of D.
Notice again the pattern of W-W-H-W-W-W-H. There is a single step between the F sharp and the G, and a single step between the C sharp and the D. This is the major scale starting on the key of D. The major scale can begin on any key.
Songs based on a scale play only the notes in that scale. For example, if we were composing a song based in the key of C major, then we could use the following notes: C, D, E, F, G, A, B. We would rarely, if ever, use any of the sharps and flats in this composition. These seven notes would comprise all the notes we use in that composition.