How can I replace 2-prong receptacles in a code compliant way?
According to the National Electrical code, you have a few options. Depending on the situation, there are a few code sections to pay attention to.

National Electrical Code 2014
Article 406 - Receptacles, Cord Connectors, and Attachment Plugs (Caps)
406.4 General Installation Requirements.
(D) Replacements. Replacement of receptacles shall comply with 406.4(D)(1), (D)(2), and (D)(3) as applicable. Arc-fault circuit-interrupter and ground-fault circuit-interrupter type receptacles shall be installed in a readily accessible location.

Where a Grounding Means Exists
If there is a grounding conductor in the box, or the box itself is properly grounded. Then a 3-prong grounding type receptacle should be installed, and the receptacle should be grounded using approved means.

(1) Grounding-Type Receptacles. Where a grounding means exists in the receptacle enclosure or an equipment grounding conductor is installed in accordance with 250.130(C), grounding-type receptacles shall be used and shall be connected to the equipment grounding conductor in accordance with 406.4(C) or 250.130(C).

Where No Grounding Means Exists
If there is not a grounding conductor in the box, and the box itself is not grounded.  There are a few options.

(2) Non–Grounding-Type Receptacles. Where attachment to an equipment grounding conductor does not exist in the receptacle enclosure, the installation shall comply with (D)(2)(a), (D)(2)(b), or (D)(2)(c).


You can simply replace the 2-prong receptacle with another 2-prong receptacle.

(a) A non–grounding-type receptacle(s) shall be permitted to be replaced with another non–grounding-type receptacle( s).


You can replace the 2-prong receptacle with a ground-fault circuit interrupting device. Though the device must be labeled &quot;No Equipment Ground&quot;, and a grounding conductor should not be connected to this or any downstream devices.

(b) A non–grounding-type receptacle(s) shall be permitted to be replaced with a ground-fault circuit interrupter-type of receptacle(s). These receptacles shall be marked “No Equipment Ground.” An equipment grounding conductor shall not be connected from the ground-fault circuit interrupter-type receptacle to any outlet supplied from the ground-fault circuit-interrupter receptacle.


You can install a ground-fault circuit interrupting device upstream, and install a 3-prong receptacle in this location. Though you'll have to label the receptacle &quot;No Equipment Ground&quot;, and &quot;GFCI Protected&quot;. No equipment grounding conductor should be connected to the receptacle.

(c) A non–grounding-type receptacle(s) shall be permitted to be replaced with a grounding-type receptacle(s) where supplied through a ground-fault circuit interrupter. Grounding-type receptacles supplied through the ground-fault circuit interrupter shall be marked “GFCI Protected” and “No Equipment Ground.” An equipment grounding conductor shall not be connected between the grounding-type receptacles.



Provide Other Protection Where Required
Where GFCI Protection is Required
If ground-fault circuit interruption is required, a ground-fault circuit interruption device should be installed. These devices do not require a grounding conductor, so can be installed in a circuit without a ground.

(3) Ground-Fault Circuit Interrupters. Ground-fault circuit-interrupter protected receptacles shall be provided where replacements are made at receptacle outlets that are required to be so protected elsewhere in this Code.

Where AFCI Protection is Required
If arc-fault circuit interruption is required, an arc-fault circuit interruption device should be installed. These devices do not require a grounding conductor, so can be installed in a circuit without a ground.

(4) Arc-Fault Circuit-Interrupter Protection. Where a receptacle outlet is supplied by a branch circuit that requires arc-fault circuit interrupter protection as specified elsewhere in this Code, a replacement receptacle at this outlet shall be one of the following:
(1) A listed outlet branch circuit type arc-fault circuit-interrupter receptacle.
(2) A receptacle protected by a listed outlet branch circuit type arc-fault circuit interrupter type receptacle.
(3) A receptacle protected by a listed combination type arc-fault circuit interrupter type circuit breaker.

Where Tamper-Resistant Receptacles are Required
If tamper-resistant receptacles are required, a tamper-resistant device should be installed.

(5) Tamper-Resistant Receptacles. Listed tamper-resistant receptacles shall be provided where replacements are made at receptacle outlets that are required to be tamper-resistant elsewhere in this Code.

Where Weather-Resistant Receptacles are Required
If weather-resistant receptacles are required, a weather-resistant device should be installed.

(6) Weather-Resistant Receptacles. Weather-resistant receptacles shall be provided where replacements are made at receptacle outlets that are required to be so protected elsewhere in this Code.