I really don’t know the detail. Dunno if you’ve seen the film enigma, but in my mind it’s a bit like those “computers” constantly whirling and chugging until they find the code!
With Bitcoin there’s only ?21m coins so in the early days anyone with a decent connection could mine them, but obviously as the number decreases, the energy needed to find them increases. A few companies have started locating their “mines” in places such as Siberia to aid with cooling costs etc