A man has been lashed 40 times with a cable after he woke to find four bearded men in his bedroom in Sydney's west, police say.

The 31-year-old man was asleep in his unit in Melton Street, Silverwater, when he woke to find four unknown men in his bedroom about 1am yesterday.

Three of the intruders allegedly restrained him on the bed, while the fourth used a cable to lash him 40 times.

The attack lasted about 30 minutes, police said.

The four men then left the flat.