NOTE: CD prevents you from adding more than 5 images, so you'll see links after I hit the limit.
Imagine a 5x5 grid with a starting position S and a finish position F:
Next, imagine yourself standing at S and looking at the squares you can travel to in one jump. For the purposes of this exercise, we'll say you can only jump in cardinal directions one space. Mark the spaces you can make it to with a distance. For this first step, there are only two squares we can reach and they both have a distance of 1:
Now, mark your starting location (S) as visited and don't let your algorithm go back to S again. Next, choose the square that has the lowest distance value that also hasn't been visited (since both of the squares have a distance of 1, we'll just choose the first one). We'll use green as the square that we're currently working with:
Assign distance values from your current square. All of our jumps from current square to next square will have a distance of 1 in this exercise. Make sure you remember that you've already "traveled" a distance of 1, so add that value (also known as your current square's distance) to the distances you're assigning:
Mark your current square as visited. Then, go back through the list of squares you haven't visited and pick the one with the lowest distance value.
Repeat the distance process but with one difference. If you come to a square that already has a distance value, only change that value if the distance value you've calculated from your current square is smaller. Typical implementations of this algorithm set all distances to infinity, knowing that they'll be overwritten as the algorithm plays out:
http://i.imgur.com/WoRvqYM.png
Keep moving to the closest unvisited square, marking distances, and repeating and your graph will look like it does below. Note that you can add a little optimization here if you find your finish square early but, for the purposes of this exercise, we'll ignore that:
http://i.imgur.com/YAGNoSs.png
After that, it's a matter of starting at your finish square, finding the lowest distance value, moving to that square and repeating. This will leave you with the shortest path from start to finish:
http://i.imgur.com/mx3VLWx.png
Here's is an example with a square we're not allowed to go to. Note that there are actually 2 shortest paths and that you'll have to use additional logic to choose one (I chose to make as few turns as possible):
http://i.imgur.com/C8l6cLx.png
A huge benefit of Dijkstra's Algorithm is that, for static environments, it can be calculated ahead of time and stored in memory. Then all you have to know is where you are and where you want to go and the shortest path from S to F will have already been found.