Why is golf 18 holes?

The Old course at St. Andrews evolved into 9 holes 'out' and 9 holes'back' to the start. This became the default for all courses.

More about why golf courses are 18 holes.

Early Scottish courses varied in the number of holes they had and the range was at least as wide as 12 holes at Prestwick to the 22 holes St. Andrews did have at one stage. 

In 1764 the golfers at St.Andrews decided to combine four short holes in to two longer holes and this reduced the total number of holes on that course at that time to 18. Over a long period of time 18 slowly evolved as the 'standard' when new courses were created.