Our brain does it through something like energy minimization given billions of years of data by leveraging the laws of physics and chemistry.
Humanity has done its best to reverse engineer this process.
It started from understanding the fundamental building block of the brain, the neuron, when Golgi figured out staining. Others built on this work and we discovered that our brain is an incredibly complex mess of 100 billion neurons and a quadrillion connections between these neurons called synapses.
And that the biggest part of our brain, the cerebrum, is broadly the same building block copied over and over again with the simple functions of inhibition or excitation through action potential.
Broadly.
In truth, we barely understand it (but we do understand much more than my simplified description that I wrote for the intro).
We do know it has a remarkably efficient ability to map the data distribution of reality.
So how do we make sand think?
We copy other stardust that can think.