Many preys retreat into a refuge as a response to the presence of a predator, a behavioural strategy which guarantees safety but is also costly due to a trade-off between hiding time and time spent in other essential activities. The balance between costs and benefits of hiding, which are influenced by different factors, determine the hiding duration. In a field experiment, the anti-predator behaviour of the mud crab Austrohelice crassa was studied to assess the effects of two factors, body size and neighbour density, on the time spent hiding in burrows following a predator threat. Hiding times, body size (estimated from burrow diameter) and neighbour density (number of other burrows within a 30 cm radius) were measured for 158 individual crabs during a snorkelling survey. Regression analyses showed that hiding time of individual crabs significantly increased with increasing body size, and decreased with increasing neighbour density. These trends are the result of three main selective pressures: size-biased predation risk, dilution of predation in dense clusters of burrows, and more intense competition in dense clusters. Variation among individual crabs probably reflects differences in the balance between costs and benefits for crabs differing in body size and neighbour density.