How do you not get lost between measures? For example, if I start on measure 28 and the the next measure down is measure 40, how do I not play early or late?
A few ways:
By counting the measures! It really is that simple. You start on measure 28, so measure 29 is your first measure of rest, then measure 30, then measure 31, etc. By the time measures 38 and 39 come up, you should be mentally and physically preparing to play again in measure 40. I always tried to interact physically in some way; typically I would use my hands to keep track in groups of five measures: measure 34 would be four fingers up, 35 all five fingers, 36 goes back to 1 finger, etc.
Through the use of musical cues. For instance, if you know that the oboe player comes in with a new theme in measure 38, you don't have to worry about counting until then. This is where very basic score study comes in; get your hands on a score and use the information you gain to your advantage! (You can also just count to determine when the oboe comes in, of course.)
Just by knowing the music. Honestly, this is how most professional musicians do it. If you go to an opera concert and look down into the pit, you'll see trombone players playing games on their smartphones until a few bars before they come in. They don't have to count, they don't have to look at the score, they just know the pieces inside and out and know when they come in. This comes with just knowing the piece; listen to it as much as you can, and try to listen to it with a score whenever possible!
Generally speaking, I recommend always counting in the first few rehearsals of a new piece, even if you think you know the piece. Eventually you'll feel comfortable enough to graduate to Step 2. Only when you really know the piece should you even think about moving to Step 3. (And some musicians will swear that you should never, ever do Step 3, just to be on the safe side!)
Richard's answer is great, and you can use all that stuff, but another thing is if you know the number of measures of rest then you can use it in your count like so: if there are 20 measures of rest in 4/4 then you count 1-2-3-4, 2-2-3-4, 3-2-3-4, ...... 19-2-3-4, 20-2-3-4. This way you easily keep count of the measures.
Richard's answer is correct and very useful, however misses points which are essential - to me at least. I'm going to fill in some important intermediate steps to reach the goals already outlined - which seems highly called for in the case of someone who is asking a question like this. (Note your question is not clear: Richard has assumed you're asking how to count many bars of rests. I'll also assume this.)
Counting: The key thing you need to know is how many bars you have to count - which should be trivially visible/countable on the score and comes with any knowledge of the piece. The example given is slightly misleading, because the actual bar #s are never relevent. (Other than the fact you can count a long gap by subtracting the bar# of the bar you finish on from the bar number you come in on.)
I don't recommend getting into the habit of making physical motions, although you can get away with just fingers if you really want to. It doesn't look good and will be noticed.
You then count the bars. Assuming 4/4 timing, you'd be counting in your head: 1,2,3,4... 2,2,3,4.... 3,2,3,4.... and so on and on upwards. I.e. you are replacing the "one"/first count of each bar with the bar number. This can very rapidly become easy and automatic. With experience, it can easily be done on new pieces you've never seen - the rhythm of counting is so ingrained you do it and read ahead to get the total # of bars to count at the same time.
Cues: Musical cues are essential for parts that don't play continuously, especially many percussion instruments. Score access/study is not important - it should become obvious where the major transitions are on your own part and what they correspond to aurally. Think tempo, dynamics, key changes, complete style changes, etc. These CAN be used to make educated guesses when you're totally lost. Richard's representation of this topic is a more advanced application of the technique: the same thing with more subtle markers that need more learning and possible more annotating your music.
Generally you will learn the sequence of major cues in a piece, and only need to count from one of these unmissable points closest to your entry.
The "shape" of the music is highly relevent. A huge volumne of music has a very regular structures, usually being based around 4 or 8 bar chunks which will be highly audible (although varying with style) and frequently quite visible on your part to the eye that's looking for it. Being able to hear when the whole ensumble passes one of these "checkpoints" is a key corrector of "off by one" counting errors i.e. gets you out of trouble when you're not sure if you dropped a bar or not, etc. This is a key skill which comes with general experience, and piece familiarity.
Jamerack beat me in the typing race with the same key point (and better formatting!) but... posting anyway since I bothered to, and there's some more info here.
When you practice by yourself at home, skip the rests. Honestly, why sit in silence for 30-something beats and waste your time when there is no one else playing with you? Just briefly stop to signify there's a rest, and then keep playing. When you play with other people, you can remember when to come in by what they're playing, or just count. 1-2-3-4, 2-2-3-4, 3-2-3-4, so on.