Suppose, I have a triangular garden with sides of $25$ feet, $40$ feet and $55$ feet. If I want to surround my garden with pillars set $5$ feet apart, how many pillars will I need?
I calculated the triangle's perimeter and divided it by $5$. I got 24.
Since it is a enclosed area, I will need one less pillar. So I will need a total of $23$ pillars.
But someone suggested me that I actually need $22$ pillars, but he didn't explain why. So am I miscalculating something?
Your reasoning for $23$ pillars seems to be flawed, as explained in another answer. This is a variation of the classic "fencepost" problem.
So if the requirement is that the pillars must be five feet apart measured along the perimeter, you need $24$ pillars, and $23$ are not sufficient.
But if the requirement is merely that each pillar must be no more than $5$ feet from two others, then there is a trick answer.
First put a pillar at each vertex of the triangle and at intervals of $5$ feet along each side. This takes $24$ pillars.
Next, let's look at the vertex between the sides of length $25$ and $55$. The angle between these sides is slightly less than $42$ degrees. If we look at the pillars $5$ feet away from the vertex on each side, those two pillars are less than $3.6$ feet apart. So you can take away the pillar at the vertex and still have every pillar no more than $5$ feet from two others.
Now let's look at the vertex between the sides of length $40$ and $55.$ The angle between these sides is slightly less than $25$ degrees. If we look at the pillars $10$ feet away from the vertex on each side, those two pillars are less than $4.3$ feet apart. So you can take away the pillar at the vertex and the two pillars $5$ feet from the vertex, and still have every pillar no more than $5$ feet from two others.
According to this interpretation, then, you can remove $4$ pillars from the original $24$ (one at one vertex, three at or near the other vertex) and enclose your garden with $20$ pillars spaced $5$ feet apart.
I don't imagine that this is the intended solution; it is just a play on the ambiguous statement of the question.
Indeed, one might ask how a set of pillars can "enclose" a garden when they are $5$ feet apart and one can simply walk in or out between two pillars. To "enclose" a garden one might imagine using the pillars as fence posts and stringing wires or rails or some other material between them. In that case, if you only use $20$ pillars as suggested in my "trick" interpretation, the wires or rails will cut off two corners of the garden. To really enclose a garden by a fence using fence posts connected by straight line segments, you truly do need $24$ fence posts. If the sides had not been chosen to be multiples of $5$ but had been some other three random numbers adding to $120,$ for example $26, 40, 54,$ you would need more than $24$ fence posts in order to have one at every vertex.