The evolution of sociality is facilitated by the recognition of close kin, but if kin recognition is too accurate, nepotistic behaviour within societies can dissolve social cohesion. In social insects, cuticular hydrocarbons act as nestmate recognition cues and are usually mixed among colony members to create a Gestalt odour. Although earlier studies have established that hydrocarbon profiles are influenced by heritable factors, transfer among nestmates and additional environmental factors, no studies have quantified these relative contributions for separate compounds. Here, we use the ant Formica rufibarbis in a cross-fostering design to test the degree to which hydrocarbons are heritably synthesized by young workers and transferred by their foster workers. Bioassays show that nestmate recognition has a significant heritable component. Multivariate quantitative analyses based on 38 hydrocarbons reveal that a subset of branched alkanes are heritably synthesized, but that these are also extensively transferred among nestmates. In contrast, especially linear alkanes are less heritable and little transferred; these are therefore unlikely to act as cues that allow within-colony nepotistic discrimination or as nestmate recognition cues. These results indicate that heritable compounds are suitable for establishing a genetic Gestalt for efficient nestmate recognition, but that recognition cues within colonies are insufficiently distinct to allow nepotistic kin discrimination.