Why not just put the whole cost through when you buy it?
Because the asset will earn its keep over several years, and charging it all to the year of purchase makes that year look terrible and every later year look better than it was. Depreciation matches the cost to the years that benefit from it.
The mechanics are simple. Decide how long the asset will last and what it will be worth at the end, and charge the difference evenly over that period. Straight-line, as this is called, is the method most small businesses use. Reducing-balance charges a fixed percentage of the remaining value each year, so more early on.
Depreciation is a non-cash cost. No money leaves the business when it is charged; the money left when the asset was bought. That is why it is added back when working out cash flow, and why EBITDA exists.