First, let's address your concern with "I have 4 GPIO pins and 5 devices to connect. Can I multiplex two devices, and how?"
"Can I multiplex two devices?" Yes, but it makes no
sense - you need to save up a pin and multiplexing only two devices you save nothing. Multiplex 3,4 or all 5.
You can't multiplex any without a minimal amount of external hardware.
Now let's think what you want: You could minimize the number of
transistors, and multiplex "3 on 2" while driving the other 2
directly. You'll have a fairly complex hardware solution, and a fairly
simple if a little messy software for it. Nevertheless, this answer is
definitely EE, with a small mess of software and big mess of hardware,
boiling down to "How do I build a 2-to-4 demux in discrete parts?"
Or you can get a 3-to-8bit demux chip, use 3 GPIO pins for address,
one possibly for latch or value or whatever extra you like, or even get a
4-to-16 demux chip, and multiplex up to sixteen devices using the 4
GPIO. It will be fairly simple electronically and completely trivial
from programming point of view. Again, EE answer "How do I use a
3-to-8 demux chip?" as the hardware part despite being simple is much
more complex than the absolutely trivial software part.
Simply put the question is an EE question about demultiplexers, not a microcontroller question - the 4 GPIO could be anything.
Let us try something else:
"What is the least number of GPIO pins I need to use to read a 12-key keyboard in a way that detects multiple simultaneous keypresses? How does the complexity grow with decreasing number of pins?"
You will need scanning in software. You will need to design which lines to drive, which to read. Following a bunch of designs starting with a plain 2x3 grid of inputs and outputs and scanning each x each combination, a capacitor charge based timing key identification with some 3 pins, through something with 2 pins and a shift register down to 1 GPIO pin using some 1w protocol to talk to an intelligent keyboard over serial interface. That's actual embedded design. It's still not specific to any microcontroller but it definitely poses a software challenge - or design challenge. Only EE knowledge is not enough.