Most music that deals with functional harmony can be described as a journey from the tonic, or home key, and back to the tonic again via other key centres. In essence, your piece could start in C major as its overall key centre, wander through some other keys as well as C to eventually end up at C major again. There are exceptions to this rule, but as a basis for understanding functional harmony, it’s a good place to start.
A good way to move your key centre around is with a device that is often referred to in jazz as a two (minor), five (dominant 7th), one. If you use the numbers to represent chords, the home key is C major (1), chord 2 would be D minor and chord 5 would be G dominant 7th. This is used everywhere in classical music, jazz and songwriting: anywhere where there is functional harmony (in other words, not serialism or modal music). Their role is to cadence (which means to go, or to go back) into the key centre, thus strengthening the sense of the key. The other interesting thing is that if you have a 2-5-1 in C major, with the 1 chord being C major, then you can use the C major scale over all three. This is useful to know when improvising or walking over these chords. To practise these, have one bar of the 2 chord (D minor, for example) and one bar of the 5 chord (G7) plus two bars of the 1 chord (C major), then try to play a walking bass-line between the chord changes, hitting the root note of the chord on the first beat of every bar using triads and chromaticism. Practise this at a range of different tempos.
The best way to get into understanding this is a combination of studying, practising in the way I describe above, and also learning by ear. By listening to music you can emulate, internalise and try yourself on your own instrument. Great players to listen to in the jazz idiom for this are Ron Carter, Ray Brown and Paul Chambers. Transcribe their walking basslines for a deeper understanding of how to negotiate chord sequences – which often involve 2-5-1s – in your walking basslines and soloing.