This project uses two groups of eight LEDs sharing eight GPIO pins via one of my Pi interfaces. The anodes of each group of LEDs are commoned and driven by a BFY51 transistor.
The two transistors are controlled by a further two GPIO pins to select either one or the other group. To make things nicer looking, the LEDs are mounted in the form of two circles. The circuit diagram can be seen on the right whilst the photograph below shows the project connected to a Raspberry Pi.
To turn an LED ON, its GPIO pin has to go low, to allow current to flow. At the same time its selector line has to go high to turn the transistor ON. This is quite straight forward as long as the LEDs to be lit are in the same group.
Should you want to light LEDs that are members of both groups at the same time and not connected to the same GPIO pin, multiplexing has to be used. This means that your program must send signals to turn the selected LEDs on and off in rapid succession. If this is done fast enough, the eye is deceived into thinking that all LEDs are on at the same time. It is a technique commonly used with LED displays.
If you feel really creative, you could combine this multiplexing with pulse width modulation in order to change the brightness of the LEDs. By varying the on-off proportion of the signal supplying an LED an apparent change of brightness can be produced.
For more detail: LED circles using multiplexing