Artificial neural networks are performing tasks, such as image recognition and classification, that were thought only accessible to the brain. However, these algorithms run on traditional computers and consume orders of magnitude more energy more than the brain does at the same task. One promising path to reduce the energy consumption is to build dedicated hardware to perform cognitive tasks. Nanodevices are particularly interesting because they allow for complex functionality with low energy consumption and small size. I discuss two nanodevices. First, I focus on stochastic magnetic tunnel junctions, which can emulate the spike trains emitted by neurons with a switching rate that can be controlled by an input. Networks of these tunnel junctions can be combined with CMOS circuitry to implement population coding to build low power computing systems capable of processing sensory input and controlling output behavior. Second, I turn to different nanodevices, memristors, to implement a different type of computation occurring in nature: swarm intelligence. A broad class of algorithms inspired by the behavior of swarms have been proven successful at solving optimization problems (for example an ant colony can solve a maze). Networks of memristors combined with CMOS circuitry can perform swarm intelligence and find the shortest paths in mazes. These results are striking illustrations of how matching the functionalities of nanodevices with relevant properties of natural systems open the way to low power hardware implementations of difficult computing problems.