There are two reasons to derate the ampacity of a conductor. One is ambient temperature and the other is the proximity to other current carrying conductors. If the temperature exceeds 104° or there are more than three current carrying conductors in a raceway, the ampacity drops.

Start with table 310.15(B)(16). Find the wire type and gauge to determine the allowed ampacity. It can be 60°,75°, 90° depending on the insulation type. For example THWN is found in the 75° column while THWN-2 is found in the 90° column.

Next is the temperature. Table 310.15(B)(2)(b) gives the percentage of the ampacity that is permitted at a given temperature. For example, at 125° a wire found in the 90° column of table 310.15(B)(16) is allowed 84% of the ampacity that table 310.15(B)(16) identified.

Here is an example: 12 awg THHN wire is in an attic with an ambient temperature of 113°. Using the tables: 30 amps x .95 = 28.5 amps.

There is another consideration for raceways and cables exposed to sunlight on a roof. Table 310.15(B)(3)(c) provides a temperature adder depending on the height above the roof.

Moving on we come to the issue of more than three current carrying conductors in a raceway. That takes you to table 310.15(B)(3)(a). Wires in proximity to expanding and collapsing magnetic fields have a current generated within them. That current is small and worthless but it will generate unwanted heat. So as a result, if there are more than three the is a percentage of the ampacity given in table 310.15(B)(16) that is allowed based on the number of conductors.

Here is an example: There are 18 THHN #12 awg wires in a conduit. Table 310.15(B)(3)(a) allows 50% of the ampacity given at table 310.15(B)(16) 30 amp x .5 = 15 amp.
Note that neutral conductors that carry the unbalanced current of multiwire circuits are not counted as a current carrying conductor.

As an example I'll use the most common 12 awg which is THWN-2. That wire is found in the 90° column and has an ampacity of 30 amps. The raceway is 8" above the roof and table 310.15(B)(3)(c) requires the addition of 30° in temperature to the ambient 113° in the example. At 141° the value found in table 310.15(B)(2)(b) is 71% . 30 amp x .71 = 21.3amp.