A very common thing in the world of microcontrollers: “I got too few IOs!”. Depending on your project you might get away with this little trick: Shift Registers

As you can see, you can easily use shift registers as IO-expanders. It is a compact and easy solution. You only need three pins from your microcontroller (data, clock, latch). And even better: it is cascadable! you can hook up as many registers as you want. The QS-Pin ist shifting the data straight out to the next register and so on.
I only drew the schematic as an example for an output, but of course there are shit registers for inputs.

CAUTION: Be careful with this circuit if you have tight timing constraints. Because the serial data communication is not the fastest, you might get in trouble with this one. Espacially with long chains.