Where can I find accurate info on what determines maximum sockets?

I’ve googled to try and find this out, but every site I read seems to be wrong. e.g One said items could have maximum four sockets on nightmare. But I used the cube recipe to socket a cedar bow on nightmare and it got 5 sockets.

My info is, maximum sockets is possible at least on nightmare act2 and further.

The problem with socket via cube recipe is, the number of sockets is random.

This is true however the item still cant roll more sockets than the item level allows so u will never be able to roll 6 sockets on a crystal sword found in normal for an example.