Miniweb is a proof-of-concept implementation of the TCP/IP protocol stack together with a webserver that uses around 30 bytes of RAM. The TCP/IP stack and the webserver uses around 30 bytes of RAM. The code is written in C and constitutes around 400 lines, comments removed. It should be possible to further minimize the code size and memory usage. Note: this code is not intended for actual use, it is only meant for educational purposes! Miniweb is just a proof of concept that shows that it is indeed possible to implement a TCP/IP stack and a web server using very small amounts of RAM. For a full-scale TCP/IP stack, refer to uIP or lwIP. Miniweb was written by Adam Dunkels at the Swedish Institute of Computer Science.


In order to reduce RAM usage, Miniweb stores its web pages as precomputed IP/TCP packets complete with headers. When sending the packets, only a few fields are updated and the checksums adjusted. Incoming packets are processed one byte at a time and therefore there is no need to buffer the data. The checksum is computed when each byte is received and if the checksum is found to be incorrect when the entire packet has been received, the contents of the packet is not used for further processing.

There are two variants of Miniweb, a stateless variant and a statefull variant. The stateless variant is a bit smaller and uses less RAM, but does not provide the same functionality as the statefull variant.

The stateless Miniweb

The stateless Miniweb keeps only minimal state information. Instead of keeping connection state, the stateless Miniweb uses the acknowledgement numbers of the incomming ACKs to decide which TCP segment to send. The IP address, port number and TCP sequence number of the last received ACK is also saved so that if an ACK is lost, the corresponding segment can be retransmitted. This means that if an ACK in another "connection" arrives before the retransmission occurs, the state of the previous connection is lost, and the retransmission will never occur. This connection will hang until the application in the other end sends data.

It it important to note that this approach of course is totally and utterly wrong; a system using this approach should not be connected to an actual network, let alone the global Internet!

To make matters worse:

  • Miniweb does not support multiple TCP connections
  • There is no support for dynamic content

Table 1. Number of lines of code and RAM usage in the stateless Miniweb. The total RAM usage varies between 24 and 28 bytes depending on the number of bytes used for pointers on the system for which Miniweb is compiled. The number of lines of code are approximate.
Protocol Function Lines of code Bytes of RAM
TCP and IPChecksum calculation23
IPInput processing436
IPOuput processing264 - 8
TCPInput processing757
TCPOutput processing38 
TCPDropping connections after too many retransmissions41
TCPDropping stale connections40
HTTPDifferentiating between web pages21
Total  24 - 28

The stateful Miniweb

The stateful variant of Miniweb is activated by a compile time option (-DSTATEFUL) and uses 5-7 bytes of extra RAM. This variant actually keeps connection state and might therefore be considered to be a more "real" TCP/IP implementation. It also does congestion control, making it even more "real".

Congestion control

The stateful version of miniweb features a very minimal congestion control mechanism; it implements the slow start algorithm. The rationale behind this is that a webserver of this magnitude will most likely only serve small files and images, and for such small transfers the congestion avoidance phase is never entered anyway.

Testing Miniweb

If you have a FreeBSD box you can test Miniweb directly. Linux users need to download the universal tun/tap network interface and compile it into their kernel.

Download the code and do:

gunzip -c miniweb.tar.gz | tar xvf -
cd miniweb

Now you should have the Miniweb TCP/IP stack and web server running on IP address You can try it out by clicking on the link. Note that it isn't possible to use ping to reach the TCP/IP stack.

To inspect the packets that are sent to and from Miniweb, run

tcpdump -l -n -S -i tun0


Some links to other small TCP/IP stacks plus web servers using the same ideas that Miniweb uses:

  • iPIC - A Match Head Sized Web Server.
  • webACE - World's Smallest Web Server.
  • WWWpic2 - Small HTTP/TCP/IP implementation for a PIC.
  • PIC Web Server - Small HTTP/TCP/IP/SLIP PIC implementation.

$Date: 2005/11/11 12:21:48 $