The open strings, on the keyboard
Open strings E, A, D, G, B and E.
The open strings are E, A, D, G, B and E, from low to high. The gaps between them decide whether a shape keeps its form when you move it across the neck.
Where the next string begins
5 string pairs. The odd one is G to B, which is fret 4.
Each ringed note is played on one string and matches the open note of the next string up. On every pair but one, that note is at fret 5. The exception is G to B, which is fret 4. The strings are tuned in four fourths and a third, and that one third is why a shape learned on the low strings comes out wrong on the top two.
Standard tuning does not use the same distance between every pair of strings. From low E to A is five semitones, an interval called a perfect fourth, and so are A to D and D to G. From G to B is four semitones, a major third. From B to E is a fourth again. That makes four fourths and one third, and the third sits between the third string and the second.
That single exception is why a shape learned on the lower strings comes out wrong when you carry it onto the top two. Every note you move across the gap between G and B has to sit one fret higher than the pattern suggests. Guitarists often learn this as a rule about the B string, but the string itself is not the cause. The tuning is uneven in exactly one place, and the B string is where you meet it.
A bass tuned entirely in fourths has no exception, which is why bass shapes move across the strings unchanged.