Security in mobile ad hoc networks is difficult to achieve, notably because of the vulnerability of wireless links, the limited physical protection of nodes, the dynamically changing topology, the absence of a certification authority, and the lack of a centralized monitoring or management point. Earlier studies on mobile ad hoc networks (MANETs) aimed at proposing protocols for some fundamental problems, such as routing, and tried to cope with the challenges imposed by the new environment. These protocols, however, fully trust all nodes and do not consider the security aspect. They are consequently vulnerable to attacks and misbehavior. More recent studies focused on security problems in MANETs, and proposed mechanisms to secure protocols and applications. This article surveys these studies. It presents and discusses several security problems along with the currently proposed solutions (as of July 2005) at different network layers of MANETs. Security issues involved in this article include routing and data forwarding, medium access, key management and intrusion detection systems (IDSs). This survey also includes an overview of security in a particular type of MANET, namely, wireless sensor networks (WSNs).