Before composing a song, you will select a "Mode" for it. This could be "Ionian (natural major)", "Aeolian (natural minor)", Dorian, etc.
This "Mode" provides the tone-material for the song. A mode is always based on a scale. A basic scale that is used for composing does mostly have seven tones. You can build chords on this scale by layering thirds – or to put it more simply: By skipping every second tone of the scale.
So if you are composing within the key, you are only using seven different tones, and that's it. ☝️ BUT it can be nice and refreshing to use a chord that is not within the key and, thus, is using different tones and is based on a different scale.
You can borrow a chord from a different scale other than the scale your song is written in. The only thing you have to do is to use a different scale or key and create chords on this scale.
👉 For example, you are composing a song in "C Ionian major" this scale will be the base of the chords and melodies:
👉 You could go ahead and borrow a chord from the "C Aeolian minor" scale that has the following tones:
If we build chords on this scale by layering thirds, we will get different ones than with the Ionian scale (obviously).
For example, if we create a chord on the first tone of the "C Aeolian" scale, we will get a "C minor" chord. We can now go ahead and use this chord in our "C major" song.
You can build chords on any tone of the "C Aeolian" or other scales and add them to your song. This is called "Borrow a chord" or Modal interchange.