Relationship between $N$ and $\phi(N)$ in the RSA algorithm Recently I started learning how the RSA algorithm works and there is one single part of the computation which really confuses me and can't get over it.

Let's say I chose 2 prime numbers,

namely 

$P = 3$ and $Q = 11$

$N = 3 \times 11 = 33$

$\phi(N) = (P-1)\times(Q-1) = 20$

Now, I have to chose e based on some criteria (as per RSA), let $e = 7$
Now, I have to determine $d$ by using, $e^{-1} \equiv1 (\bmod \phi(N))$
When I encrypt and decrypt,

a) cipher = $m ^ e \bmod N$

b) message = $c ^ d \bmod N$

In the above case, instead of $\bmod N$, for the same example, I tried different $N$ than the actual $N$ ($33$), it didn't work for any other number other than $33$. Why is it so? I can feel since finding $d$ is based on inverse under $\bmod \phi(N)$, there is some relation between $N$ and $\phi(N)$, but couldn't get my head on it.

Is there some relation between $N$ and $\phi(N)$, if so, how can I learn about it in detail?
RSA is based on some mathematical theorems. The first theorem that you need to learn is the Euler's Theorem;  if $n$ and $a$ are coprime positive integers, then

$$a^{{\varphi (n)}}\equiv 1\bmod n.$$ when $n$ is a prime it is the Little Fermat Theorem.

This theorem tell us that in the power we use modulo $\varphi(n)$, i,e, $$a^{x} \equiv a^{x \bmod\varphi(n)} \bmod n $$

When one performs the textbook RSA encryption one calculates $$c = m^e \bmod n$$ and decryption performed as $$m = c^d \bmod n$$

Now, explicitly;

$$c^d = (m^{e})^d = m^{ed}$$ Since we choose $d$ as the inverse of $e$ modulo $\varphi(n)$, $e\cdot d = 1 \bmod \varphi(n),$ then

$$ m^{ed \bmod \varphi(n)} = m^1 = m \bmod n$$


  I tried different N than the actual N (33), it didn't work for any other number other than 33. Why is it so?


Because the calculations that you performed uses modulus other than defined. $m^e$ will be a different number in a different modulus.



Note that: You used $\varphi(n) = (p-1)(q-1)$ when $n=pq$. Normally Chamichael lambda $\lambda(n)$  is used $\lambda(n)=\operatorname{lcm}(p-1,q-1)$ and $$\varphi(n)=\lambda(n)\cdot\gcd(p-1,q-1).$$ This gives smallest $d$ to operate.

Note 2: In the above textbook RSA is used which should never be used without proper padding. For encryption, one should use RSA-OAEP which is introduced by M. Bellare, P. Rogaway. Optimal Asymmetric Encryption -- How to encrypt with RSA and PKCS#1 v1.5 padding. The former is preferable since it has security proof and PKCS#1 v1.5 PKCS1v1.5 encryption is inherently hard to use securely and should not be used.

Actually, we don't use RSA for encryption, We prefer hybrid encryption. RSA is mostly used for signatures and for signatures RSA is used with Probabilistic Signature Scheme (PSS). Again this is introduced by M. Bellare, P. Rogaway; PSS: Provably Secure Encoding Method for Digital Signatures

Remember, RSA Signing is Not RSA Decryption