To calculate challenge rating in 5e, you need to consider both the defensive and offensive statistics of a creature. A creature with a 1/8 challenge rating (CR) typically has an AC of 13, 735 hit points, and a +3 attack bonus. Compared to a CR 10 creature, which has an average of 17 AC, 206220 hit points, and a +7 attack bonus.
On page 274 of the Dungeon Master’s Guide, you can find a table that shows the various defensive and offensive elements that go into determining a creature’s monster rating:
— Defensive —  — Offensive —  

CR  Xp  +Prof. Bonus  AC  Hit Points  Attack Bonus  Damage/Round  Save DC 
0  10  +2  13  16  +3  01  13 
1/8  25  +2  13  735  +3  23  13 
1/4  50  +2  13  3649  +3  45  13 
1/2  100  +2  13  5070  +3  68  13 
1  200  +2  13  7185  +3  914  13 
2  450  +2  13  86100  +3  1520  13 
3  700  +2  13  101115  +4  2126  13 
4  1,100  +2  14  116130  +5  2732  14 
5  1,800  +3  15  131145  +6  3338  15 
6  2,300  +3  15  146160  +6  3944  15 
7  2,900  +3  15  161175  +6  4550  15 
8  3,900  +3  16  176190  +7  5156  16 
9  5,000  +4  16  191205  +7  5762  16 
10  5,900  +4  17  206220  +7  6368  16 
11  7,200  +4  17  221235  +8  6974  17 
12  8,400  +4  17  236250  +8  7580  18 
13  10,000  +5  18  251265  +8  8186  18 
14  11,500  +5  18  266280  +8  8792  18 
15  13,000  +5  18  281295  +8  9398  18 
16  15,000  +5  18  296310  +9  99104  18 
17  18,000  +6  19  311325  +10  105110  19 
18  20,000  +6  19  326340  +10  111116  19 
19  22,000  +6  19  341355  +10  117122  19 
20  25,000  +6  19  356400  +10  123140  19 
21  33,000  +7  19  401445  +11  141158  20 
22  41,000  +7  19  446490  +11  159176  20 
23  50,000  +7  19  491535  +11  177194  20 
24  62,000  +7  19  536580  +11  195212  21 
25  75,000  +8  19  581625  +12  213230  21 
26  90,000  +8  19  626670  +12  231248  21 
27  105,000  +8  19  671715  +13  249266  22 
28  120,000  +8  19  716760  +13  267284  22 
29  135,000  +9  19  760805  +13  285302  22 
30  155,000  +9  19  805850  +14  303320  23 
Here’s how to use that table:

Defensive Challenge Rating. First, look at your monster’s hit points and note the associated challenge rating. Then, look at the suggested AC for that hit point value. If the monster’s AC is at least two points higher or lower than challenge rating suggested by its hit points, adjust the CR up or down by 1 for every 2 points of difference.

Offensive Challenge Rating. Determine the monster’s average damage per round. Note that the “damage per round” numbers in this table assume that all attacks land. For example, if a monster has multiattack and each of its attacks deals an average of 5 damage, its damage per round is 10 (even though, realistically, not all of its attacks will land, and its real DPR will be lower) (DMG 277 – Step 11).
Once you know the monster’s damage per round, find it on the table above and note the challenge rating associated with it. Then, look at the attack bonus or save DC (whichever is more relevant for the monster’s damage) suggested for that challenge rating. If it’s at least two points higher or lower than the challenge rating indicated by its damage per round, adjust the CR up or down by 1 for every 2 points of difference.

Average Challenge Rating. Finally, average the defensive and offensive challenge ratings. Round the average up or down to the nearest challenge rating that exists. For example, if your monster’s offensive challenge rating is 9 and their defensive challenge rating is 6, their final challenge rating is 8 (7.5 rounded up).
Once you’ve determined a monster’s CR, you can assign its proficiency bonus.
Dungeon Master’s Guide, page 2747
Other Considerations for a Creature’s Challenge Rating

Resistances and Immunities. A creature with resistances or immunities has more “effective hit points,” which you need to consider as its actual hit points when determining its Defensive Challenge Rating. The DMG suggests the following multipliers, dependent on what CR bracket the creature belongs to:
Expected CR Resistance HP Mod Immunity HP Mod 14 x2 x2 510 x1.5 x2 1116 x1.25 x1.5 17+ x1 x1.25 
Special Traits, Spellcasting, Actions, and Reactions. If special traits, spells, actions, and reactions significantly alter a monster’s offensive or defensive CR (by increasing their damage per round or effective hit points, for example), it may increase a creature’s CR.

Flying Speed. A creature with flying speed has +2 effective AC when determining its defensive challenge rating — if it can deal damage at range and currently has a CR of 10 or lower.

Saving Throw Proficiencies. If a monster has three or more saving throw bonuses, it has +1 effective AC when determining its defensive challenge rating; if it has 4 bonuses, it has +2 effective AC; if it has 5+ bonuses, it has +4 effective AC.

Monster Features. Many monster features can increase their CR by changing their offensive or defensive challenge ratings. Here are all of the listed monster features that impact a monster’s CR in some way:
Feature  Effect on CR 

Aggressive  Increase the monster’s effective perround damage output by 2. 
Ambusher  Increase the monster’s effective attack bonus by 1. 
Angelic Weapons  Increase the monster’s effective perround damage output by the amount noted in the trait. 
Avoidance  Increase the monster’s effective AC by 1. 
Blood Frenzy  Increase the monster’s effective attack bonus by 4. 
Breath Weapon  For the purpose of determining effective damage output, assume the breath weapon hits two targets, and that the target each fails its saving throw. 
Brute  Increase the monster’s effective perround damage by the amount noted in the trait. 
Charge  Increase the monster’s damage on one attack by the amount noted in the trait. 
Constrict  Increase the monster’s effective AC by 1. 
Damage Transfer  Double the monster’s effective hit points. Add onethird of the monster’s hit points to its perround damage. 
Dive  Increase the monster’s damage on one attack by the amount noted in the trait. 
Elemental Body  Increase the monster’s effective perround damage by the amount noted in the trait. 
Enlarge  Increase the monster’s effective perround damage by the amount noted in the trait. 
Fiendish Blessing  Apply the monster’s Charisma modifier to its actual AC. 
Frightful Presence  Increase the monster’s effective hit points by 25% if the monster is meant to face characters of 10th level or lower. 
Horrifying Visage  Increase the monster’s effective hit points by 25% if the monster is meant to face characters of 10th level or lower. 
Innate Spellcasting  The impact that Innate Spellcasting has on a monster’s challenge rating depends on the spells that the monster can cast. Spells that deal more damage than the monster’s normal attack routine and spells that increase the monster’s AC or hit points need to be accounted for when determining the monster’s final challenge rating. 
Legendary Resistance  Each perday use of this trait increases the monster’s effective hit points based on the expected challenge rating. 
Magic Resistance  Increase the monster’s effective AC by 2. 
Martial Advantage  Increase the monster’s effective perround damage by the amount gained by this trait. 
Nimble Escape  Increase the monster’s effective AC and effective attack bonus by 4 (assuming the monster hides every round). 
Pack Tactics  Increase this monster’s effective attack bonus by 1. 
Parry  Increase the monster’s effective AC by 1. 
Possession  Double the monster’s effective hit points. 
Pounce  Increase the monster’s effective damage for 1 round by the amount it deals with the bonus action gained from this trait. 
Psychic Defense  Apply the monster’s Wisdom modifier to its acual AC if the monster isn’t wearing armor or wielding a shield. 
Rampage  Increase the monster’s effective perround damage by 2. 
Regeneration  Increase the monster’s effective hit points by 3 * the number of hit points the monster regenerates each round. 
Relentless  Increase the monster’s effective hit points based on the expected challenge rating: 14, 7 hp; 510, 14 hp; 1116, 21 hp; 17 or higher, 28 hp. 
Shadow Stealth  Increase the monster’s effective AC by 4. 
Spellcasting  The impact that Spellcasting has on a monster’s challenge rating depends on the spells that the monster can cast. Spells that deal more damage than the monster’s normal attack routine and spells that increase the monster’s AC or hit points need to be accounted for when determining the monster’s final challenge rating. 
Stench  Increase the monster’s effective AC by 1. 
Superior Invisibility  Increase the monster’s effective AC by 2. 
Surprise Attack  Increase the monster’s effective damage for 1 round by the amount noted in the trait. 
Swallow  Assume the monster swallows one creature and deals 2 rounds of acid damage to it. 
Undead Fortitude  Increase the monster’s effective hit points based on the expected challenge rating: 14, 7 hp; 510, 14 hp; 1116, 21 hp; 17 or higher, 28 hp. 
Web  Increase the monster’s effective AC by 1. 
Dungeon Master’s Guide page 2801
Example Challenge Rating Calculation 5e
I create a monster with the following statistics:
AC  Hit Points  Attack Bonus  Damage/Round  Save DC 

15  135  6  25  14 
It also has resistance to nonmagical weapon damage and the Avoidance feature.
Here’s how to calculate its CR:

Defensive Challenge Rating. My monster has 135 hit points, which suggests a CR of 5. However, with that expected CR and nonmagical weapon damage, this moster’s “effective HP” is 202 (135 x 1.5). This suggests a CR of 9.
With the Avoidance feature, the monster’s effective AC goes from 15 to 16. This is within range of a CR 9 monster, so we are finished calculating the monster’s Defensive Challenge Rating.

Offensive Challenge Rating. This monster’s damage per round is 25, which indicates a CR of 3. However, since their attack bonus of +6 indicates a CR of 5, we need to increase that CR of 3. The difference here in CR is 2, so we increase the original CR 3 to an Offensive Challenge Rating of 4.

Average Challenge Rating. The monster’s Defensive Challenge Rating is 9, and its Offensive Challenge Rating is 4, so its Average Challenge Rating is 7 (6.5 rounded up). Finished!