With the increased application of wireless sensor networks (WSNs) to military, commercial, and home environments, securing the data in the network has become a critical issue. Several security mechanisms, such as TinySec, have been introduced to address the need for security in WSNs. The cost of security, however, still mostly remains an unknown variable. To provide a better understanding of this cost we have studied three aspects of WSNs security: encryption algorithms, modes of operation for block ciphers, and message authentication algorithms. We have measured and compared their memory and energy consumption on both MicaZ and TelosB sensor motes. The results of our experiments provide insight into the suitability of different security algorithms for use in WSN environments and could be used by WSN designers to construct the security architecture of their systems in a way that both satisfies the requirements of the application and reasonably uses the constrained sensor resources.