There are times (quite often in fact) when you will be playing a song in one key, just for example, let's say the key of C, and you will come upon a chord which doesn't really exist in that particular key, but hey, there it is. It sounds perfectly fine though (in the context of whatever particular chord progression that you're playing) so maybe you won't think about exactly how this chord “fits” in.
Let's look at a few chord progressions in C to demonstrate this, okay? Try them out yourself if you want to.
1) C Bb F C 2) C E7 Am Dm D7 G C 3) C A D G C
Now, as we were saying, since the key of C has no flats or sharps, any chord that contains any flat or sharp is not actually part of the key of C. Where did it come from?
What music theory tries to do is to look at these chords in terms of how they fit into the flow of the chord progression. All chord progressions are simply movements from one point to the next, hopefully they will eventually bring us back to the home (or root) chord.
Sometimes in moving from one point to the next, we are actually “borrowing” chords from other keys (here the Bb in #1, the E7 and D7 in #2 and the A and D in #3). Theory tries to label these chords in terms of the keys from which they are borrowed. We (usually) try to determine where they came from by where they are going to (how they are resolved).
Just to make sure we're on the same page, let's look at the primary and secondary chords in the key of C major, shall we?
I II III IV V VI (VII) C Dm Em F G Am (Bdim)
Are you with me? Okay, in example one (C, Bb, F, C) we need to ask about that Bb. C, F, C we already can make out as I, IV, I. Since the Bb is aiding in the transition from C to F, let's theorize (I know bad pun) that Bb must have some relation to F. And sure enough if we look at the chords in an F major scale we will see:
I II III IV V VI (VII) F Gm Am Bb C Dm (Edim)
In the F scale, Bb is IV. But what we want to do as music theorists is to give the Bb some kind of context in the key of C. So we have to relate it somehow to a chord in the key of C and that's exactly what we do - we call it IV “of” IV, meaning that it is the IV of F (which is the IV of C).
Almost always (and yes there are ALWAYS exceptions) an “of” chord will be a IV or V of something. In example #2 (C, E7, Am, Dm, D7, G, C) we borrow two chords (the E7 and D7) from other places. Again if you listen to where the chords take you, it's fairly easy to establish that the E7 is resolving to Am and the D7 to G. So we would write out this progression like this:
C E7 Am Dm D7 G C I V of VI VI II V of V V I
Are you still with me on this? Because sometimes, just to show you how tricky things can get, a chord might not be resolving to one of the chords of a given key. Then you have to be a bit of a detective to figure things out. Example #3 (C, A, D, G, C) is a typical example of this sort of thing. Here not only are A and D obviously “borrowed” from other keys, but the A resolves to the D which, since D is not part of the C chord group, presents us with a bit of a problem.
What we do in this case is to work backwards. Let's mark what we know, okay?
C A D G C I ? ? V I
Since G is the resolution for the D chord, we can (and rightly so!) make the case for D to be V of V. But that still leaves us with the A chord. But since A is the V of D, we basically create a secondary layer to describe how the A relates to the G. A would be V of V in G, correct? So we basically write that out in terms of the G to the C -
C A D G C I V of V of V V of V V I
This is an absolutely fascinating concept that many writers use (even though they may not know it). If you'd like to get a bit better handle on it, I suggest you read my column You Say You Want A Resolution.