You can improvise over almost any song once you know how it works. But where do we start? How do we know what to play?
During a song, even one with many instruments, the music is usually centered around one chord at a time. Since most chords are made of 3 or 4 notes, that means the whole band is usually sticking to those notes.
The exception is the melody! The melody will often utilize a whole scale, and the melody is where we will typically focus our efforts on guitar for the time being.
So, the question becomes what scale should we use? To answer that, we need to know which chord is the Tonic. In other words, which chord feels like home?
Most often, the Tonic is simply the first chord in the progression. For example, in the progression:
C - F - G - C
The Tonic is a C Major chord.
So, you can probably guess that we can play the C Major Scale over the C Major Chord, but in fact we can play the same C Major Scale over the entire chord progression!
That means you're ready to improvise right now over a C-F-G-C chord progression as long as you know how to play the Major Scale in C. Another valid choice would be the Major Pentatonic.
If the Tonic was a Minor Chord - of course we'd use a Minor Scale or Minor Pentatonic.
But sometimes, the first chord in the progression is NOT the tonic. For example, in the following progression:
Dm - G7 - C - C
Although we start on Dm, the Tonic is actually still C. Try playing the chord progression, can you hear it? Notice the way the C chord makes you feel, it's a relief of tension. Looking for that feeling can help you find the Tonic.
In more complex songs, you may find that even when you've correctly identified the Tonic, some chords seem to clash with the scale. For example, in this variation of the previous chord progression, A7 won't quite fit:
Dm - G7 - C - A7
That's because A7 is Non-Diatonic. To know what that means, you need to have a grasp of Major Diatonic Chords, which you may not yet!
But don't worry, there's a simple answer for what to do with a Non-Diatonic Chord.
We simply stick to the notes of the outlier chord while it's being played.
A7 is made up of 4 notes: A, C#, E, and G. (No wonder this chord clashes with the C Major Scale! It contains a C#.)
So, while the rhythm section of the band is playing the Dm, G7, or C chords you are free to use the C Major Scale as before, but when the A7 chord is played, you need to switch to improvising using just those 4 notes.
There's many ways we could approach that - and it generally takes some preparation to do effectively, but let's quickly take a look at how those notes overlap with C Major.
The C Major Scale
The Notes of A7
Don't worry if you aren't ready to play along with a progression like that. Just keep in mind that any chord can always be played along with effectively by sticking to the notes it uses.
And that's all you need to know to get started! Even in difficult genres like jazz, it generally boils down to the same principles.
Learning to write effective and interesting melodies is another story entirely, but now you have the know-how necessary to play along with just about anything.