An RGB LED is three LEDs in one package: one red, one green, one blue. Each has its own pin. Drive each pin with PWM and you can vary the contribution of each colour independently. Your eye does the mixing.
Additive colour, just like a screen
The trick is the same one your phone uses 60 times a second: additive colour mixing. All three at full = white. R full, G half, B off = orange. R off, G full, B full = cyan. There are 256³ ≈ 16.7 million possible combinations — the same gamut as 24-bit colour.
Three analogWrite calls do it: analogWrite(R, 255); analogWrite(G, 128); analogWrite(B, 0);. Cycling the values produces a slowly shifting hue. Picking values from an HSV-to-RGB function lets you sweep cleanly around the colour wheel.
The catch: common anode vs common cathode
RGB LEDs come in two flavours. Common-cathode means the shared pin goes to ground and each colour pin sources current (255 = bright). Common-anode means the shared pin goes to 5 V and the colour pins sink current (255 = OFF, 0 = bright — your code is inverted). Check the datasheet. Setting the wrong polarity is the most common reason a "broken" RGB LED only shows white.