For example if I create something similar to a Goblin I am able to tell it should have 7 hit points but I don’t know how 2d6 is determined.
7 (2d6) is just a form of shorthand.
As you probably know, “2d6” means “two six-sided dice”. The “7” is just the average of the rolls. There’s a simple equation you can use to determine the average of dice rolls:
$$Dice_{ValueAverage} = frac{Dice_{Quantity}+(Dice_{Sides}*Dice_{Quantity})}2.$$
Does it seem complicated? Try this, then:
$$x = frac{y+zy}2.$$
“x” is the average you are looking for. “y” is how many dice you are rolling. “z” is how many sides are on the dice.
In the case of 2d6, the equation looks like this:
$$7 = frac{2+(6*2)}2$$
$$7 = frac{2+12}2$$
$$7 = frac{14}2$$
So, that’s the explanation of how the hit points are determined. 7 is the average value of 2d6. This means that a goblin cursed by the gods will have as few as 2 hp and one that was blessed by the gods will have as much as 12 hp. (Not much of a blessing, if you ask me…)
If you want to retroactively determine hit dice from a preferred average hit points, you just work backwards. Let’s say you want a monster with an average of 27 hit points. Generally, the way to do it is by working with a size chart. If you’d rather determine the size later, though, you’ll be left with 3 dice choices: d4, d8, and d10. Any other dice value will result in an average value different than 27.
Here’s the way of finding out the dice values, though:
$$27 = frac{27*2}2$$
$$27 = frac{54}2$$
Because 27 is the average value, you need to multiply it by 2 in order to get the middle value. This means “(y+zy)” should equal 54. Because we usually round down half-values in D&D, “27.5” is considered the same as “27” for our purposes, expanding the final value of “(y+zy)” to ultimately include either 54 OR 55, but no value higher or lower than these two. (If you wish to see the math for the result of 55, I can add it at your request, but it really is just a matter of following these same steps with “27.5” instead of “27”.)
$$27 = frac{y+zy}2$$
Here, we reach variables. Because we know “y” has to be the number of faces on a dice, we don’t have to worry about y being greater than 20 or less than 4. Because we know “x” is the number of dice being rolled, we don’t have to worry about x being a negative number. This makes our large list of possible outcomes very much more contained. The number of Dice Sides (z) we have for our creature’s hit dice can only be 4 (d4), 6 (d6), 8 (d8), 10 (d10), 12 (d12), and 20 (d20). This gives us 12 equations to test. (Because we need a final value of 27 OR 27.5.)
$$27 = frac{y+(4*y)}2$$
$$27.5 = frac{y+(4*y)}2$$
$$27 = frac{y+(6*y)}2$$
$$27.5 = frac{y+(6*y)}2$$
$$27 = frac{y+(8*y)}2$$
$$27.5 = frac{y+(8*y)}2$$
$$27 = frac{y+(10*y)}2$$
$$27.5 = frac{y+(10*y)}2$$
$$27 = frac{y+(12*y)}2$$
$$27.5 = frac{y+(12*y)}2$$
$$27 = frac{y+(20*y)}2$$
$$27.5 = frac{y+(20*y)}2$$
While I admit this looks intimidating, it’s really not that difficult to work through. Just take it one step at a time through each equation. After all, at this point, you just need to find “y”.
Equation 1:
$$27 = frac{y+(4*y)}2$$
You need to get rid of the “2” that it is being divided by, so multiply both sides by 2.
$$27*2 = (frac{y+(4*y)}2)*2$$
$$54 = y+(4*y)$$
$$54 = y+4y$$
“4y” is just another way of saying “y+y+y+y”, so let’s simplify this together.
$$54 = y+y+y+y+y$$
$$54 = 5y$$
Now, just divide 5 from both sides.
$$54/5 = 5y/5$$
$$10.8 = y$$
Well, it looks like that wasn’t quite right. Let’s try the steps again, but this time let’s work with 27.5.
Equation 2:
$$27.5 = frac{y+(4*y)}2$$
Multiply both sides by 2.
$$27.5*2 = (frac{y+(4*y)}2)*2$$
$$55 = y+(4*y)$$
$$55 = y+4y$$
Simplify.
$$55 = y+y+y+y+y$$
$$55 = 5y$$
Divide 5 from both sides.
$$55/5 = 5y/5$$
$$11 = y$$
As you can see, we got “11” as our result. If we replace “y” in the original equation with “11”, we get the following:
$$27.5 = frac{11+4(11)}2$$
$$27.5 = frac{11+44}2$$
$$27.5 = frac{55}2$$
$$27.5 = 27.5$$
With this, we find that by using “x=27.5” (which rounds down to 27), “y=11”, and “z=4” (to represent a 4-sided dice), it takes 11d4 to get the average of 27.5. I’m going to continue the other equations for examples.
Equation 3:
$$27 = frac{y+(6*y)}2$$
$$27*2 = (frac{y+(6*y)}2)*2$$
$$54 = y+(6*y)$$
$$54 = y+6y$$
$$54 = y+y+y+y+y+y+y$$
$$54 = 7y$$
$$54/7 = 7y/7$$
$$7.7 = y$$
Equation 4:
$$27.5 = frac{y+(6*y)}2$$
$$27.5*2 = (frac{y+(6*y)}2)*2$$
$$55 = y+(6*y)$$
$$55 = y+6y$$
$$55 = y+y+y+y+y+y+y$$
$$55 = 7y$$
$$55/7 = 7y/7$$
$$7.85 = y$$
Result: You cannot get an average of 27 or 27.5 by using only 6-sided dice.
Equation 5:
$$27 = frac{y+(8*y)}2$$
$$27*2 = (frac{y+(8*y)}2)*2$$
$$54 = y+(8*y)$$
$$54 = y+8y$$
$$54 = y+y+y+y+y+y+y+y+y$$
$$54 = 9y$$
$$54/9 = 9y/9$$
$$6 = y$$
Result: You only need 6d8 in order to get an average of 27. Equation 6 is unnecessary.
Equation 7:
$$27 = frac{y+(10*y)}2$$
$$27*2 = (frac{y+(10*y)}2)*2$$
$$54 = y+(10*y)$$
$$54 = y+10y$$
$$54 = y+y+y+y+y+y+y+y+y+y+y$$
$$54 = 11y$$
$$54/11 = 11y/11$$
$$4.9 = y$$
Equation 7:
$$27.5 = frac{y+(10*y)}2$$
$$27.5*2 = (frac{y+(10*y)}2)*2$$
$$55 = y+(10*y)$$
$$55 = y+10y$$
$$55 = y+y+y+y+y+y+y+y+y+y+y$$
$$55 = 11y$$
$$55/11 = 11y/11$$
$$5 = y$$
Result: You only need 5d10 in order to get an average of 27.5.
I could be a completionist, but I think you get the point. It’s just basic algebra after this point. As long as you understand the math, it’s pretty easy to retro-engineer any average HP value you want.